Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Later
-
2.11.0
-
None
-
None
Description
If I validate the "instance.xml" with the XML Schema "test.xsd" I get the following error:
cvc-identity-constraint.4.3: Key 'kr' with value 'a2' not found for identity constraint of element 'parent'.
I tested on the xml-schema-1.1-dev branch.
Xerces discards all the key defined on "child" elements except the ones defined on the last "child" element. In the example only the "a1" and "a4" values are used when the keyref is checked.
The schema added below defines a key on the "child" element selecting the "element/@id" attribute and a key reference on the "parent" element that specifies that "test/@ref" points to "child/element/@id" attributes.
All the keys defined in the "child" elements should be valid, except the ones that are duplicates. There is a discussion about this on the XML Schema Dev list:
http://lists.w3.org/Archives/Public/xmlschema-dev/2013Jan/0004.html
---- instance.xml------------------
<?xml version="1.0" encoding="UTF-8"?>
<parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<child>
<element id="a1"/>
<element id="a2"/>
</child>
<child>
<element id="a1"/>
<element id="a4"/>
</child>
<test ref="a2"/>
<test ref="a1"/>
</parent>
-------------------
-----------test.xsd--------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="parent">
<xs:complexType>
<xs:sequence>
<xs:element name="child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="element">
<xs:complexType>
<xs:attribute name="id" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="k">
<xs:selector xpath="element"/>
<xs:field xpath="@id"/>
</xs:key>
</xs:element>
<xs:element name="test" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="ref"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:keyref name="kr" refer="k">
<xs:selector xpath="test"/>
<xs:field xpath="@ref"/>
</xs:keyref>
</xs:element>
</xs:schema>
----------------------------------