XPath correction applied only on the first Path in Field.XPath class
--------------------------------------------------------------------

         Key: XERCESJ-1137
         URL: http://issues.apache.org/jira/browse/XERCESJ-1137
     Project: Xerces2-J
        Type: Bug
    Versions: 2.7.1    
    Reporter: George Cristian Bina


In Field.java on the inner XPath class there is the following comment and code:

// NOTE: We have to prefix the field XPath with "./" in
            //       order to handle selectors such as "@attr" that 
            //       select the attribute because the fields could be
            //       relative to the selector element. -Ac
            //       Unless xpath starts with a descendant node -Achille Fokoue
            //      ... or a / or a . - NG
            super(((xpath.trim().startsWith("/") 
||xpath.trim().startsWith("."))?
                    xpath:"./"+xpath), 
                  symbolTable, context);

>From this it is clear that the XPath Paths should be corrected to start with 
>./ if they do not start with . or / but only the first one is corrected.
Thus an instance like:
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="test.xsd">
  <a>
    <id1>v1</id1>
  </a>
  <a>
    <id1>v2</id1>
  </a>
</test>

will be reported invalid against test.xsd:
<?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|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>

Replacing:
<xs:field xpath="./@id1|./@id2|id1|./id2"/>

with 

<xs:field xpath="./@id1|./@id2|./id1|./id2"/>\

makes Xerces report that the schema is valid.

Regards,
George




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.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