Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jun 7, 2006

Traverse All the Nodes of a DOM Tree

This is just a litle method that illustrates how to get the minimum of information from all nodes of a DOM tree. The key of this method is the "old-school" recursive style:

 private void traverseAllNodes(Node node)
   {   
   if(node.hasChildNodes())
     {    
     NodeList NL=node.getChildNodes();            
     for(int i=0;i<NL.getLength();i++)
       {
       Node childnode=NL.item(i);
                
       System.out.print("Name:"+childnode.getNodeName());
       System.out.print("Value:"+childnode.getNodeValue()+"\n");
                                      
       viewAllNodes(childnode);
       }
     }
   }  
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap