DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=27955>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=27955 getElementById does not work Summary: getElementById does not work Product: Xerces2-J Version: 2.6.2 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Critical Priority: Other Component: DOM AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Using this schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="root"> <xs:annotation> <xs:documentation>Comment describing your root element</xs:documentation> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element name="someElement" type="IdentityType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="IdentityType"> <xs:sequence> <xs:element name="someOtherElement" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:ID" use="required"/> </xs:complexType> </xs:schema> And this XML file: <?xml version="1.0" encoding="UTF-8"?> <root> <someElement id="id1"> <someOtherElement> Text 1</someOtherElement> </someElement> <someElement id="id2"> <someOtherElement> Text 2</someOtherElement> </someElement> <someElement id="id3"> <someOtherElement> Text 3</someOtherElement> </someElement> <someElement id="id4"> <someOtherElement> Text 4</someOtherElement> </someElement> <someElement id="id5"> <someOtherElement> Text 5</someOtherElement> </someElement> </root> I get null on getElementById. This class demonstrates the problem: public class TestXercesId { private DocumentBuilder builder = null; public static void main(String[] args) { URL schema = TestXercesId.class.getResource("/test-xerces.xsd"); TestXercesId test = new TestXercesId(schema); InputStream xml = test.getClass().getResourceAsStream("/test-xerces.xml"); Document doc = test.parse(xml); Element id3 = doc.getElementById("id3"); System.out.println("id3: " + id3); } private TestXercesId(URL schemaURL) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute( "http://apache.org/xml/features/validation/dynamic", Boolean.TRUE); factory.setAttribute( "http://apache.org/xml/features/validation/schema", Boolean.TRUE); factory.setAttribute( "http://apache.org/xml/features/validation/schema-full-checking", Boolean.TRUE); factory.setAttribute( "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schemaURL.toExternalForm()); try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } } private Document parse(InputStream xmlDocument) { try { return builder.parse(xmlDocument); } catch (Exception e) { throw new RuntimeException(e); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
