simple help with DOM parsing - urgent
843834May 10 2005 — edited May 10 2005hi,
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