<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: [jdom-interest] traversing the JDOM tree</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Maybe something like this will help you:</FONT>
</P>
<P><FONT SIZE=2>public static List getSubElements(Element element) {</FONT>
<BR><FONT SIZE=2> List subElements = new ArrayList();</FONT>
<BR><FONT SIZE=2> traverseSubElements(element, null, subElements);</FONT>
<BR><FONT SIZE=2> return subElements;</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>public static List getSubElements(Element element, String name) {</FONT>
<BR><FONT SIZE=2> List subElements = new ArrayList();</FONT>
<BR><FONT SIZE=2> traverseSubElements(element, name, subElements);</FONT>
<BR><FONT SIZE=2> return subElements;</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>private static void traverseSubElements(Element element, String name, List elements) {</FONT>
<BR><FONT SIZE=2> List children = (name == null) ? element.getChildren() : element.getChildren(name);</FONT>
<BR><FONT SIZE=2> for (Iterator i = children.iterator(); i.hasNext();) {</FONT>
<BR><FONT SIZE=2> Element subElement = (Element)i.next();</FONT>
<BR><FONT SIZE=2> elements.add(subElement);</FONT>
<BR><FONT SIZE=2> traverseSubElements(subElement, name, elements);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>///Odd Moller</FONT>
</P>
<BR>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Vivek Kapadekar [<A HREF="mailto:vkapadekar@bitfone.com">mailto:vkapadekar@bitfone.com</A>]</FONT>
<BR><FONT SIZE=2>Sent: den 15 april 2003 18:59</FONT>
<BR><FONT SIZE=2>To: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>Subject: [jdom-interest] traversing the JDOM tree</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=2>hi </FONT>
<BR><FONT SIZE=2>I am using JDOM for the first time. It looks really cool, but one</FONT>
<BR><FONT SIZE=2>functionality that I am looking for which is missing in it. And that is</FONT>
<BR><FONT SIZE=2>for traversing the JDOM tree.</FONT>
<BR><FONT SIZE=2>The getChild and getChildren gets only the elements one level deep. What</FONT>
<BR><FONT SIZE=2>If i want to recursively find and Element or check existence of an</FONT>
<BR><FONT SIZE=2>element, like getElementByName() or findElement().</FONT>
</P>
<P><FONT SIZE=2>Thanks</FONT>
</P>
<P><FONT SIZE=2>--Vivek</FONT>
</P>
<BR>
<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2><A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com" TARGET="_blank">http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</A></FONT>
</P>
</BODY>
</HTML>