[jdom-interest] traversing the JDOM tree

Odd Moller odd.moller at cypoint.se
Wed Apr 16 00:38:55 PDT 2003


Maybe something like this will help you:

public static List getSubElements(Element element) {
   List subElements = new ArrayList();
   traverseSubElements(element, null, subElements);
   return subElements;
}

public static List getSubElements(Element element, String name) {
   List subElements = new ArrayList();
   traverseSubElements(element, name, subElements);
   return subElements;
}

private static void traverseSubElements(Element element, String name, List
elements) {
   List children = (name == null) ? element.getChildren() :
element.getChildren(name);
   for (Iterator i = children.iterator(); i.hasNext();) {
      Element subElement = (Element)i.next();
      elements.add(subElement);
      traverseSubElements(subElement, name, elements);
   }
}

///Odd Moller


-----Original Message-----
From: Vivek Kapadekar [mailto:vkapadekar at bitfone.com]
Sent: den 15 april 2003 18:59
To: jdom-interest at jdom.org
Subject: [jdom-interest] traversing the JDOM tree



hi 
I am using JDOM for the first time. It looks really cool, but one
functionality that I am looking for which is missing in it. And that is
for traversing the JDOM tree.
The getChild and getChildren gets only the elements one level deep. What
If i want to recursively find and Element or check existence of an
element, like getElementByName() or findElement().

Thanks

--Vivek


_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030416/c35cd553/attachment.htm


More information about the jdom-interest mailing list