OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] code challenge

[ Lists Home | Date Index | Thread Index ]

> 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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS