Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1393

Identity constraint is not enforced on xs:anySimpleType

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0
    • 3.0.0
    • None
    • Windows XP SP2, Visual C++ 6.0

    Description

      I have this schema file

      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

      <xs:element name="Songs">
      <xs:complexType>
      <xs:sequence>
      <xs:element name="Song" maxOccurs="unbounded">
      <xs:complexType>
      <xs:attribute name="title" use="required"/>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>

      <xs:unique name="Song">
      <xs:selector xpath="Song"/>
      <xs:field xpath="@title"/>
      </xs:unique>
      </xs:element>

      </xs:schema>

      It defines a root named "Songs" with child nodes named "Song" having one attribute, with no type specified (so, it is assumed to be xs:anySimpleType).
      It also defines a uniqueness constraint to avoid having two "Song" element with the same title.

      I also have an XML associated with this schema,

      <Songs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd_unique.xsd">
      <Song title="Hotel California"/>
      <Song title="Hotel California"/>
      </Songs>

      that lists the same song twice.

      However, running "Saxcount -n -s xsd_unique.xml" on the XML file result in no validation errors being reported.

      But changing the schema to say

      <xs:attribute name="title" type="xs:string" use="required"/>

      makes the validator report "Duplicate unique value declared for identity constraint of element 'Songs'."

      The cause of the error is in

      inline int AnySimpleTypeDatatypeValidator::compare(const XMLCh* const,
      const XMLCh* const
      , MemoryManager* const)
      {
      return -1;
      }

      that always report two instances of xs:anySimpleType to be different, regardless of their values.

      Strictly speaking, this is not an error, as the XMLSchema specs say (§ 2.2.1.2, Simple Type Definition):

      "The mapping from lexical space to value space is unspecified for items whose type definition is the ·simple ur-type definition·. Accordingly this specification does not constrain processors' behaviour in areas where this mapping is implicated, for example [...] checking identity constraints involving such items.
      Note: The Working Group expects to return to this area in a future version of this specification."

      Anyhow, this causes confusion in the users (because Xerces-J reports the error, for instance) so I would like to do one (or both) of the following changes:
      1) implement the "compare" operation to do a lexical space comparation (i.e. using XMLString::equals)
      2) emit a warning when an identity field involves a xs:anySimpleType

      Feedback?

      Alberto

      Attachments

        Activity

          People

            amassari Alberto Massari
            amassari Alberto Massari
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: