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

Key/keyref constraints: values of the QName type are not supported

    XMLWordPrintable

Details

    • 1.3
    • generic
    • generic

    Backports

      Description

        Name: eaR10174 Date: 10/08/2003


          Key/keyref constraints are not applied to elements' values in case when the type of the
        values is QName and they have prefixes (see test.java, test.xsd, test.xml below).

          The bug appears in jdk1.5.0beta-b22 and affects new JCK1.5 tests:
          
            api/xml_schema/suntest/identity/IdentityTestSuite/002/test.html#test.2.v
            api/xml_schema/suntest/identity/IdentityTestSuite/002/test.html#test.3.n

        ------------------------------------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 test1.xml...");
                t.parse("test1.xml");
                System.out.println("");
                System.out.println("Parsing invalid test2.xml...");
                t.parse("test2.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);
                    System.out.println("Parsed " + xmlFile);
                } 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:choice maxOccurs="unbounded">
                        <xs:element name="key" type="xs:QName"/>
                        <xs:element name="ref" type="xs:QName"/>
                    </xs:choice>
                </xs:complexType>
                                                
                <!-- identity constraint -->
                <xs:key name="key">
                    <xs:selector xpath=".//tn:key"/>
                    <xs:field xpath="."/>
                </xs:key>
                <xs:keyref name="keyref" refer="tn:key">
                    <xs:selector xpath=".//tn:ref"/>
                    <xs:field xpath="."/>
                </xs:keyref>
            </xs:element>
        </xs:schema>
        ------------------------------------test1.xml-----------------------------
        <?xml version="1.0" encoding="utf-8"?>
        <tn:root xmlns:tn="foo" xmlns:p="abc">
            <tn:key> p:abc </tn:key>
            <tn:ref> p:abc </tn:ref>
        </tn:root>
        ------------------------------------test2.xml-----------------------------
        <?xml version="1.0" encoding="utf-8"?>
        <tn:root xmlns:tn="foo" xmlns:p="abc">
            <tn:key> p:abc </tn:key>
            <tn:key> p:abc </tn:key>
        </tn: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 test1.xml...
        org.xml.sax.SAXParseException: Key 'keyref' with value 'ID Value: p:abc' not found for
        identity constraint of element 'root'.
        Parsed test1.xml

        Parsing invalid test2.xml...
        Parsed test2.xml
        --------------------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: