Subject: [xsl] get all element dom tree From: 04083259@xxxxxxxxxxxxx Date: Thu, 7 Apr 2005 15:37:59 +0100 (BST) |
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 " ); }
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to test if a value it, Jaime Stuardo | Thread | RE: [xsl] get all element dom tree, Michael Kay |
[xsl] How to test if a value itn't , Jaime Stuardo | Date | Re: [xsl] doubt, Aron Bock |
Month |