Herbert Oppmann created XERCESC-1981:
----------------------------------------

             Summary: Schema validation error with empty key
                 Key: XERCESC-1981
                 URL: https://issues.apache.org/jira/browse/XERCESC-1981
             Project: Xerces-C++
          Issue Type: Bug
          Components: Validating Parser (XML Schema)
    Affects Versions: 2.8.0, 3.0.0, 3.1.0, 3.1.1
         Environment: Windows XP SP3, Command Prompt, example program DOMCount.
            Reporter: Herbert Oppmann
            Priority: Minor
         Attachments: EmptyKey.zip

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.)

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>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to