[jdom-interest] Which is the faster way ?
philip.nelson at omniresources.com
philip.nelson at omniresources.com
Sat May 26 06:17:34 PDT 2001
Right now, because getChildren creates another list and because the
implementation is a LinkedList, the getChild approach should be faster.
When getChildren returns the real backing list, I am not sure what the
answer will be, especially now that we are using ArrayList instead of
LinkedList.
> Lets say that I have the following XML Structure
>
> <RECORDS>
> <ID> 1 </ID>
> <NAME> ABHSIHEK </NAME>
> <LOCATION> BANGALORE </LOCATION>
> </RECORDS>
>
> 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 ?
>
> regards,
> Abhishek.
>
> The most exciting phrase in science, the one which heralds
> new discoveries, is not Eureka!! but 'That's Funny'
> -- Issac Asimov.
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
More information about the jdom-interest
mailing list