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

Schema validation error with empty key

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.8.0, 3.0.0, 3.1.0, 3.1.1
    • None
    • None
    • Windows XP SP3, Command Prompt, example program DOMCount.

    Description

      With the example below, the validation returns "identity constraint key for element 'Profile' not found".
      This is caused by the attribute TextId having the empty string as value, which is used as keyref in Item/Name and as key in Language/Text. Other XML parsers do not complain, and examining the W3C XML Schema specification I also did not find any reason why an empty string should not be acceptable.
      (I know of course, that it is not wise to use an empty string as key/keyref. This was done by mistake.)

      The command line used is: DOMCount.exe -v=always -s -f -n Profile.xml

      Example XML:

      <?xml version="1.0" encoding="UTF-8"?>
      <Profile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.com/Profile" xsi:schemaLocation="http://www.example.com/Profile Profile.xsd">
      <Item Id="2">
      <Name TextId=""/>
      </Item>
      <Item Id="1">
      <Name TextId="NAME1"/>
      </Item>
      <Language>
      <Text TextId="NAME1" Value="Some name"/>
      <Text TextId="" Value="Empty!"/>
      </Language>
      </Profile>

      And this example Schema:

      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:test="http://www.example.com/Profile" targetNamespace="http://www.example.com/Profile" elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xsd:element name="Profile">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="Item" type="test:ItemT" maxOccurs="unbounded"/>
      <xsd:element name="Language" type="test:LanguageT"/>
      </xsd:sequence>
      </xsd:complexType>
      <xsd:key name="Text-Id">
      <xsd:selector xpath=".//test:Language/test:Text"/>
      <xsd:field xpath="@TextId"/>
      </xsd:key>
      <xsd:keyref name="Name-TextRef" refer="test:Text-Id">
      <xsd:selector xpath=".//test:Name"/>
      <xsd:field xpath="@TextId"/>
      </xsd:keyref>
      </xsd:element>
      <xsd:complexType name="ItemT">
      <xsd:sequence>
      <xsd:element name="Name" minOccurs="0">
      <xsd:complexType>
      <xsd:attribute name="TextId" type="test:RefIdT" use="required"/>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="Id" type="xsd:unsignedInt" use="required"/>
      </xsd:complexType>
      <xsd:complexType name="LanguageT">
      <xsd:sequence>
      <xsd:element name="Text" maxOccurs="unbounded">
      <xsd:complexType>
      <xsd:attribute name="TextId" type="test:IdT" use="required"/>
      <xsd:attribute name="Value" type="xsd:string" use="required"/>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      <xsd:simpleType name="IdT">
      <xsd:restriction base="xsd:token"/>
      </xsd:simpleType>
      <xsd:simpleType name="RefIdT">
      <xsd:restriction base="xsd:token"/>
      </xsd:simpleType>
      </xsd:schema>

      Attachments

        1. EmptyKey.zip
          1 kB
          Herbert Oppmann

        Activity

          People

            Unassigned Unassigned
            oh2657 Herbert Oppmann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: