Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

simple help with DOM parsing - urgent

843834May 10 2005 — edited May 10 2005
hi,
i'm new to xml parsing and have a simple (i think) question.
i have the following xml
<record>
<header>
<id>1</id>
</header>
</record>
<record>
<header>
<id>1</id>
</header>
</record>

i'm trying to parse first the records then from a record parse the header and from it get the id in the following way:
NodeList nodeList = org.apache.xpath.XPathAPI.selectNodeList(doc, "//*[name() = 'record']");
for every element i in the nodeList
Node node1 = nodeList.item(i);
Node node2 = org.apache.xpath.XPathAPI.selectSingleNode(node, "//*[name() = 'header']");
Node node3 = org.apache.xpath.XPathAPI.selectSingleNode(node2, "//*[name() = 'id]");
String id = node3.getFirstChild().getNodeValue();
even due i run in a loop and i see node1 containing the right record the other parsing gives me the always the data of the first record.

can't i parse and then re-parse on the node i got?
if the second parsing always done from the root, even due i gave the parser another node?

what am i doing wrong?

thanks in advance
alon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2005
Added on May 10 2005
2 comments
69 views