[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

get all element dom tree

Subject: get all element dom tree
From: 04083259@xxxxxxxxxxxxx
Date: Thu, 7 Apr 2005 15:37:59 +0100 (BST)
dom get all elements
 hi
from the following tree i need to get hold of
<lastName>, <firstName> ,<Address> ,<time>, <number> elements using  java
xml dom



<top>
        <lastName>Smith</lastName>
        <firstName>j</firstName>
        <address>10 x road</address>
        <city>oxford</city>
        <date> 1999-03-04</date>
        <time>14:00:00</time>
        <number>10</number>

    </top>

i used the following but it gives me the lastName and the firstName
elements i need to get the rest  how can i do it

thanks


NodeList nodeList = doc.getElementsByTagName("lastName");
System.out.println("node list length: " + nodeList.getLength());
   if (nodeList.getLength() != 0) {
       Node lastNameNode = null;
       Node firstNameNode = null;
       for (int i=0; i<nodeList.getLength(); i++) {
           lastNameNode = nodeList.item(i);
           System.out.println(lastNameNode.getChildNodes().item(0).getNodeValue());
           Node node =  lastNameNode.getNextSibling();
           while (node != null) {
               if ("firstName".equals(node.getNodeName())){
                  System.out.println("  " +
node.getChildNodes().item(0).getNodeValue());
               break;
               }
          node = node.getNextSibling();
        }
      }
    }
else {
      System.out.println("Not found " );
    }

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.