[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] get all element dom tree
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 " ); }
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|