You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2004/03/25 20:01:25 UTC
DO NOT REPLY [Bug 27955] New: -
getElementById does not work
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: xerces-j-dev@xml.apache.org
ReportedBy: Nils_Kilden-Pedersen@countrywide.com
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: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: DO NOT REPLY [Bug 27955] New: - getElementById does not work
Posted by Joseph Kesselman <ke...@us.ibm.com>.
getElementByID() searches based on attributes whose _type_, not name, is
ID. Your document needs to be validated against a DTD or schema which
declares which attributes are IDs.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org