hi
from the following tree i need to get hold of
<lastName>, <firstName> ,<Address> ,<time>, <number> elements using java
xml dom
<top>
<lastName>Smith</lastName>
<firstName>j</firstName>
<address>10 x road</address>
<city>oxford</city>
<date> 1999-03-04</date>
<time>14:00:00</time>
<number>10</number>
</top>
i used the following but it gives me the lastName and the firstName
elements i need to get the rest how can i do it
thanks
NodeList nodeList = doc.getElementsByTagName("lastName");
System.out.println("node list length: " + nodeList.getLength());
if (nodeList.getLength() != 0) {
Node lastNameNode = null;
Node firstNameNode = null;
for (int i=0; i<nodeList.getLength(); i++) {
lastNameNode = nodeList.item(i);
System.out.println(lastNameNode.getChildNodes().item(0).getNodeValue());
Node node = lastNameNode.getNextSibling();
while (node != null) {
if ("firstName".equals(node.getNodeName())){
System.out.println(" " +
node.getChildNodes().item(0).getNodeValue());
break;
}
node = node.getNextSibling();
}
}
}
else {
System.out.println("Not found " );
}
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--