• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JDOM

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic