[Home] [By Thread] [By Date] [Recent Entries]


> However (for reasons 
> I'd rather not
> go into), I need this done in as few lines of code as 
> possible. My attempt
> is below - the use of a global looks ugly to me, but it works.
> 
> The prize is a bottle of Chianti (winner collects ;-)

First, get rid of the global, like so:

> 
> 
*  public List getChildren(Element element) {
> 
*     List elements = new ArrayList();
>     elements.add(element);
> 
>     Node child;
>     Node next = (Node) element.getFirstChild();
>     while ((child = next) != null) {
>         next = child.getNextSibling();
>             if (child.getNodeType() == Node.ELEMENT_NODE) {
>                 getChildren((Element) child);
>             }
>         }
*     return elements;
> }

Next, get rid of all the carriage returns. 

That knocks it down to about one line of code.  I like my Chianti very dry,
thank you.

-- Jeff

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member