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=25171>.
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=25171

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

           Summary: key/keyref: referred key is not found when node and its
                    child are selected
           Product: Xerces2-J
           Version: 2.6.0
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: XML Schema Structures
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]
                CC: [EMAIL PROTECTED]


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/schemaLa
nguage",
                               "http://www.w3.org/2001/XMLSchema";);

            parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSo
urce",
                               "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'.
-------------------------------------------------------------------------

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

Reply via email to