[jdom-interest] newbie question

Laurent Bihanic laurent.bihanic at atosorigin.com
Wed Dec 4 05:39:48 PST 2002

Sylvain.Thevoz at swisscom.com wrote:
> I would like to see all XML tree.

There is no way in JDOM to get a flat view of the XML tree. You'll have to 
walk the tree (using Element.getChild or getChildren + Iterator) to get to the 
elements you are interested in.
Or... use XPath (see below)

> How do you do if you want to display all contents of the <description> tags?

The easiest way to directly access nodes anywhere in the XML tree is to use 
XPath expressions and an XPath engine that supports JDOM (such as Jaxen 
(www.jaxen.org) or use the latest JDOM from CVS that integrates Jaxen).
The expression "//description" selects all the <description> elements in the 

With JDOM's latest:
    import org.jdom.xpath.XPath;

    XPath desc = XPath.newInstance("//description");
    for (Iterator i=desc.selectNodes(doc).iterator(); i.hasNext(); )
       Element e = (Element)i.next();


More information about the jdom-interest mailing list