• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDOM

 
David Jordon
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 649
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getChildren method is described in Element class:
http://www.jdom.org/docs/apidocs/org/jdom2/Element.html

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic