DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12592>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12592

xs:key xpath expression fails when using ".//" in expression

           Summary: xs:key xpath expression fails when using ".//" in
                    expression
           Product: Xerces2-J
           Version: 2.1.0
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: XML Schema Structures
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


We have a key in our schema containing an xpath selector of the form
".//contact".  This xpath expression causes what I think is an incorrect error
under some situations, one of which I can reliably reproduce (see below). 
basically, if the element containing the key contains a child element, Xerces
2.1.0 produces an error of the form "org.xml.sax.SAXParseException: Identity
Constraint error (cvc-identity-constraint.4.2.1):  element "test" has a key with
no value."  In fact all of the contact elements do in fact have a key value that
is unique, so this seems wrong to me.  If I change the XPath expression to not
use ".//contact" and instead be a relative path ("./group/group2/contact") then
the file validates correctly.  We have both the SAX validation and schema
validation features set to true on the Xerces parser:
   "http://apache.org/xml/features/validation/schema"; = true
   "http://xml.org/sax/features/validation";           = true

We've developed a test case to illustrate.  I will paste an XML Schema document,
 an instance document that validates correctly (test-a-success.xml), and an
instance document that fails with the error above (test-b-fail.xml). The only
difference between the two instance docs is the deletion of a single line (line
16).  This line represents a child element of the element on which the key is
operating, but as far as I can see should have no impact whatsoever on the key
itself. Here they are:

The schema file (test.xsd):
<?xml version="1.0"?>
  <xs:schema targetNamespace="eml://ecoinformatics.org/eml-test-2.0.0rc1"
    xmlns="eml://ecoinformatics.org/eml-test-2.0.0rc1"
    xmlns:xs="http://www.w3.org/2001/XMLSchema";>

  <xs:complexType name="person">
    <xs:sequence>
      <xs:element name="references" type="xs:string" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="optional" />
  </xs:complexType>

  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="contact" type="person" maxOccurs="unbounded"/>
        <xs:element name="party" type="person" maxOccurs="unbounded"/>
        <xs:element name="group">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="contact" type="person" maxOccurs="unbounded"/>
              <xs:element name="group2">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="contact" type="person" maxOccurs="unbounded"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>

    <xs:key name="identifierKey">
      <xs:selector xpath=".//contact"/>
      <xs:field xpath="@id"/>
    </xs:key>
  </xs:element>
</xs:schema>


The instance that fails with the incorrect error (test-b-fail.xml);
<?xml version="1.0"?>
<eml:test xmlns:eml="eml://ecoinformatics.org/eml-test-2.0.0rc1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="eml://ecoinformatics.org/eml-test-2.0.0rc1
          test.xsd">
  <contact id="id.1"/>
  <contact id="id.2"/>
  <party id="id.6">
    <references>id.2</references>
  </party>
  <group>
    <contact id="id.3"/>

    <group2>
      <contact id="id.4"/>
      <contact id="id.5">
        <references>id.2</references>
      </contact>
    </group2>
  </group>
</eml:test>



And the instance that validates successfully:
<?xml version="1.0"?>
<eml:test xmlns:eml="eml://ecoinformatics.org/eml-test-2.0.0rc1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="eml://ecoinformatics.org/eml-test-2.0.0rc1
          test.xsd">
  <contact id="id.1"/>
  <contact id="id.2"/>
  <party id="id.6">
    <references>id.2</references>
  </party>
  <group>
    <contact id="id.3"/>

    <group2>
      <contact id="id.4"/>
      <contact id="id.5">
      </contact>
    </group2>
  </group>
</eml:test>

And finally the stack trace that comes fromthe SAX parser during failure
(running in an ant build using a JUnit test that we've developed):

Buildfile: build.xml

config:

init:

test:
    [junit] Running org.ecoinformatics.emltest.SaxValidateTest
    [junit] Using Xerces: Xerces-J 2.1.0
    [junit] Validating file: test-a-success.xml
    [junit] Validating file: test-b-fail.xml
    [junit] Error on line: 16
    [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 3.769 sec
    [junit] org.xml.sax.SAXParseException: Identity Constraint error
(cvc-identity-constraint.4.2.1):  element "test" has a key with no value.
    [junit]     at
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1189)
    [junit]     at
org.ecoinformatics.emltest.SaxValidateTest$SAXValidate.runTest(SaxValidateTest.java:259)
    [junit]     at
org.ecoinformatics.emltest.SaxValidateTest.testSchemaValid(SaxValidateTest.java:113)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [junit]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:324)
    [junit]     at junit.framework.TestCase.runTest(TestCase.java:166)
    [junit]     at junit.framework.TestCase.runBare(TestCase.java:140)
    [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run(TestCase.java:131)
    [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:173)
    [junit]     at junit.framework.TestSuite.run(TestSuite.java:168)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)

BUILD SUCCESSFUL

Total time: 9 seconds

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to