Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.7.1
-
None
-
None
Description
For a schema like below
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="a"/>
</xs:sequence>
</xs:complexType>
<xs:key name="aID">
<xs:selector xpath=".//a"/>
<xs:field xpath="./@id1|./@id2"/>
</xs:key>
</xs:element>
<xs:element name="a">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="a"/>
<xs:element ref="id1"/>
<xs:element ref="id2"/>
</xs:choice>
<xs:attribute name="id1" use="optional"/>
<xs:attribute name="id2" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="id1" type="xs:string"/>
<xs:element name="id2" type="xs:string"/>
</xs:schema>
Xerces reports the following document as valid:
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
<a id2="v1" id1="v2"></a>
</test>
Instead of signaling the duplicate key value error:
SystemID: E:\workspace\oXygen\samples\test.xml
Location: 2:24
Description: E Identity constraint error: field "./@id1|./@id2" matches more than one value within the scope of its selector; fields must match unique values.
The problem is in XPathMatcher when a Path matches an attribute the matched() method is not called if there is a preceding path that was matched, in this case the matched method will be called only for the first Path ./@id1 and not for the second Path ./@id2.
Here it is the relevant code in the XPathMatcher class:
if (fCurrentStep[i] == steps.length) {
fMatched[i] = MATCHED_ATTRIBUTE;
int j=0;
for(; j<i && ((fMatched[j] & MATCHED) != MATCHED); j++);
if(j==i)
}
The matched method should be always called to allow the detection of the duplicate value that is performed in the XMLSchemaValidator (in the ValueStore). So the above code should be replaced with"
if (fCurrentStep[i] == steps.length)
{ fMatched[i] = MATCHED_ATTRIBUTE; AttributePSVI attrPSVI = (AttributePSVI)attributes.getAugmentations(aIndex).getItem(Constants.ATTRIBUTE_PSVI); fMatchedString = attrPSVI.getActualNormalizedValue(); matched(fMatchedString, attrPSVI.getActualNormalizedValueType(), attrPSVI.getItemValueTypes(), false); }Best Regards,
George
Attachments
Issue Links
- is related to
-
XERCESJ-832 element order matters on keyref checking?
- Reopened