[jdom-interest] Which is the faster way ?

Abhishek Srivastava abhisheks at india.hp.com
Sat May 26 04:22:47 PDT 2001

Hello All,

Lets say that I have the following XML Structure

	<ID> 1 </ID>

Let's say that I want to extract tne values of the document.

One way can be

Element root = doc.getRootElement();
String id = root.getChild("ID").getText();
String name = root.getChild("NAME").getText();
String loc = root.getChild("LOCATION").getText();

Other way can be

List list = doc.getRootElement().getChildren();
String id = (String)list.get(0);
String name = (String) list.get(1);
String loc = (String) list.get(2);

Which approach will be faster ?

Should I always try to travrse a JDOM Tree using the getChild APIs Or I
should first extract things to a Java Collection Object and then use it for
data extraction. Or is it that both are the same and it doesn't matter which
one i use ?


         The most exciting phrase in science, the one which heralds
         new discoveries, is not Eureka!! but 'That's Funny'
                                       -- Issac Asimov.

More information about the jdom-interest mailing list