jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes JDOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JDOM" Watch "JDOM" New topic


David Jordon

Joined: Aug 17, 2013
Posts: 6
Hi all,

I have recently started working with JDOM. I have been trying to read through the java api, but unfortunately still don't quite understand how to use some of the methods. My goal is to read an xml file and iterate through the child elements of the node, and append new nodes to wrap all the children of the root node. So, that being said, I am having a problem iterating through them as I do not know how I can get length of the elements as you would with a normal array. So seeing how I don't know how many children the xml file will have I can't just put in the value within the for loop. Does anyone have any insight as to how I can create a list of all the children elements much like you do with a normal array containing objects? Any help with that would be greatly appreciated. Here is what I have been trying so far looking at the API...

java.util.List<Element> getChildren()
This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

and also tried using this...

NodeList list = svg.getChildNodes();

I haven't really gotten what I want from this, but maybe I just haven't used all the proper import statements to collaborate with the the NodeList to get what I want from it.

Thanks in advance for any help you could offer
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 632
getChildren method is described in Element class:

Then you iterate through it. Basically, like this.

If you want to know how many in it, the basic list's size() method will do.
I agree. Here's the link: http://aspose.com/file-tools
subject: JDOM
It's not a secret anymore!