ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xml-dev
xml-dev
RE: [xml-dev] code challenge
by Jeff Lowery other posts by this author
Aug 9 2002 12:30AM messages near this date
RE: [xml-dev] code challenge | RE: [xml-dev] code challenge
>  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

-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org> , an
initiative of OASIS <http://www.oasis-open.org> 

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl> 
Thread:
Jeff Lowery
Danny Ayers
Toivo "Deutsch" Lainevool
Morten Primdahl

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved