[ 
https://issues.apache.org/jira/browse/XERCESJ-1138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12877079#action_12877079
 ] 

George Bina commented on XERCESJ-1138:
--------------------------------------

This issue is fixed by the implementation of XPathMatcher attached to 
XERCESJ-832
https://issues.apache.org/jira/secure/attachment/12446685/XPathMatcher.java

> More than one values for a key not detected
> -------------------------------------------
>
>                 Key: XERCESJ-1138
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1138
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: XML Schema 1.0 Structures
>    Affects Versions: 2.7.1
>            Reporter: George Cristian Bina
>
> 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) {
>                                     AttributePSVI attrPSVI = 
> (AttributePSVI)attributes.getAugmentations(aIndex).getItem(Constants.ATTRIBUTE_PSVI);
>                                     fMatchedString = 
> attrPSVI.getActualNormalizedValue();
>                                     matched(fMatchedString, 
> attrPSVI.getActualNormalizedValueType(), attrPSVI.getItemValueTypes(), false);
>                                 }
>                             }
>                             
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-dev-h...@xerces.apache.org

Reply via email to