Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4991020

XMLSchema: {field} 'node_name/.' is evaluated incorrectly

XMLWordPrintable

    • b41
    • generic
    • generic
    • Verified

      Name: eaR10174 Date: 02/09/2004


          RI incorrectly evaluate fields of identity constraints like 'node_name/.'. RI reports
      that an element has a key with no value. Fields like 'node_name' are evaluated correctly.
      According to the XPath specification expressions 'node_name' and 'node_name/.' are the same.

      The bug affects the following new JCK-15 beta2 test adopted from W3C XSTC-20020116 testsuite:

         api/xml_schema/msxsdtest/identityConstraint/idL077.html#idL077_i

      The sample is provided below; it fails on JDK 1.5.0-beta-b37.
      ------------------------------------test.xsd------------------------------
      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   targetNamespace="test">
           <xsd:element name="root">
               <xsd:complexType>
                   <xsd:sequence>
                       <xsd:element name="child" type="xsd:string"/>
                   </xsd:sequence>
               </xsd:complexType>

               <xsd:key name="key1">
                   <xsd:selector xpath="."/>
                   <xsd:field xpath="child/."/>
               </xsd:key>
           </xsd:element>
      </xsd:schema>
      ------------------------------------test.xml------------------------------
      <?xml version="1.0"?>
      <test:root xmlns:test="test"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="test test.xsd"
      ><child>123</child></test:root>
      ------------------------------------Test.java-----------------------------
      import java.io.File;
      import org.xml.sax.SAXException;
      import org.xml.sax.SAXParseException;
      import org.xml.sax.helpers.DefaultHandler;
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.parsers.SAXParser;

      public class Test {

           protected static class ErrorHandler extends DefaultHandler {
               public int errorCounter = 0;

               public void error(SAXParseException e) throws SAXException {
                   System.out.println(e);
                   errorCounter++;
               }

               public void fatalError(SAXParseException e) throws SAXException {
                   System.out.println(e);
                   errorCounter++;
               }
           }

           protected static SAXParser createParser() throws Exception {
               SAXParserFactory spf = SAXParserFactory.newInstance();
               spf.setNamespaceAware(true);
               spf.setValidating(true);
               SAXParser parser = spf.newSAXParser();
               parser.setProperty(
                       "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                       "http://www.w3.org/2001/XMLSchema");

               return parser;
           }

           public static void main(String [] args) {
               ErrorHandler errorHandler = new ErrorHandler();

               try {
                   SAXParser parser = createParser();
                   parser.parse(new File(args[0]), errorHandler);
               } catch (Exception e) {
                   exit(1, "Fatal Error: " + e);
               }

               if (errorHandler.errorCounter == 0) {
                   exit(0, "PASSED.");
               } else {
                   exit(1, "FAILED.");
               }
           }

           public static void exit(int errCode, String msg) {
               System.out.println(msg);
               System.exit(errCode);
           }
      }
      --------------------------------------------------------------------------
      % java -showversion Test test.xml
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)

      org.xml.sax.SAXParseException: Identity Constraint error
      (cvc-identity-constraint.4.2.1): element "root" has a key with no value.
      FAILED.
      --------------------------------------------------------------------------

      ======================================================================

            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: