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

Key/keyref: referred key is not found when node and its child are selected

XMLWordPrintable

    • b36
    • generic
    • generic
    • Verified

        Name: eaR10174 Date: 10/08/2003


          A parser reports that a referred key is not found in the context of an element in case
        when a keyref constraint refers to a key constraint with a selector that is a union xpath
        expression selecting a node and its child (see test.java, test.xsd, test.xml below).

          The bug appears in jdk1.5.0beta-b22 and affects a new JCK1.5 test:
          
            api/xml_schema/suntest/identity/idc006/idc006.nogen.html#idc006.nogen.v00

        ------------------------------------test.java-----------------------------
        import javax.xml.parsers.SAXParserFactory;
        import javax.xml.parsers.SAXParser;
        import org.xml.sax.SAXException;
        import org.xml.sax.SAXParseException;
        import org.xml.sax.helpers.DefaultHandler;

        public class test {

            protected static class ErrorHandler extends DefaultHandler {
                public void error(SAXParseException e) throws SAXException {
                    System.out.println(e.toString());
                }

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

            public static void main(String [] args) {
                test t = new test();
            
                System.out.println("Parsing valid test.xml...");
                t.parse("test.xml");
            }
            
            private void parse(String xmlFile) {
                ErrorHandler eh = new ErrorHandler();

                try {
                    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");

                    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
                                       "test.xsd");
         
                    parser.parse(xmlFile, (DefaultHandler)eh);
                } catch (Exception e) {
                    System.out.println(e.toString());
                }
            }
        }
        ------------------------------------test.xsd------------------------------
        <?xml version="1.0" encoding="utf-8"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                   xmlns:tn="foo"
                   targetNamespace="foo" elementFormDefault="qualified">
            <xs:element name="root">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="a">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element ref="tn:b"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="ref" maxOccurs="unbounded" minOccurs="0"
        type="xs:string" />
                    </xs:sequence>
                </xs:complexType>
                                                
                <!-- identity constraint -->
                <xs:key name="key">
                    <xs:selector xpath=".//tn:a/tn:b|.//tn:a/tn:b/tn:c"/>
                    <xs:field xpath="@id"/>
                </xs:key>
                <xs:keyref name="keyref" refer="tn:key">
                    <xs:selector xpath=".//tn:ref"/>
                    <xs:field xpath="."/>
                </xs:keyref>
            </xs:element>
            
            <xs:element name="c">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:string"/>
                </xs:complexType>
            </xs:element>
                        
            <xs:element name="b">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element ref="tn:c" minOccurs="0" />
                    </xs:sequence>
                    <xs:attribute name="id" type="xs:string"/>
                </xs:complexType>
            </xs:element>
        </xs:schema>
        ------------------------------------test.xml------------------------------
        <?xml version="1.0" encoding="utf-8"?>
        <root xmlns="foo">
            <a>
               <b id="id1">
                 <c id="id2"/>
               </b>
            </a>

            <ref>id2</ref>
        </root>
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b22)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b22, mixed mode)

        Parsing valid test.xml...
        org.xml.sax.SAXParseException: Key 'keyref' with value 'ID Value: id2' not found for
        identity constraint of element 'root'.
        --------------------------------------------------------------------------

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

              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: