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

Re: skipping the null node values in a DOM Tree

  • To: "Seetha Rama Krishna" <ram_kurra@y...>
  • Subject: Re: skipping the null node values in a DOM Tree
  • From: "Anthony Ettinger" <aettinger@s...>
  • Date: Wed, 7 Jun 2006 22:19:53 -0700
  • Cc: xml-dev@l...
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=UJdNl2kMHYMW5b11hNMCpKkxIAdTBEvF8tUvvgc/PENE2Sto5HkkdDcXfZK9r9plAOBiyLIHGtdAAtn7yHEnDgFfp1XRtKRBL158xRYp4CyKEEi2kKUOAsFE+ErSFqXPyFPiGqgcaQpwPp8AHeliO2FcpUrJfi/5xQWKIwtHfcs=
  • In-reply-to: <20060608050804.63867.qmail@w...>
  • References: <20060608050804.63867.qmail@w...>
  • Sender: ettinger@g...

node values
probably just need to check if it has a value before you do something with it:

if (chhh.getFirstChild().getNodeValue()) {
    //do a print
    System.out.println("NodeType 1" +chhh.getFirstChild().getNodeValue());
    applicationArrayList.add(chhh.getFirstChild().getNodeValue());
}



On 6/7/06, Seetha Rama Krishna <ram_kurra@y...> wrote:
> Hi,
>        I am having an xml file like the following
>  <application>
>          <row>
>              <id>4</id>
>              <name>CLIENTDEMO</name>
>              <description/>
>          </row>
>   </application>
>          I had written java code to iterate thru this xml and retrieve the
> values .  when the element <description>  came I am getting null pointer
> xception.
>
>      Here is my code.
>  NodeList application =
> documentElement.getElementsByTagName("application");
>      for (int i = 0; i < application.getLength(); i++)
>          {
>
>              NodeList nl = application.item(i).getChildNodes();
>              {
>                  Node ch = application.item(i);
>                  NodeList nll = ch.getChildNodes();
>                  ArrayList applicationArrayList = new ArrayList();
>                  for (int j = 0; j < nll.getLength(); j++)
>                  {
>                      Node chh = nl.item(j);
>                      NodeList nlll = chh.getChildNodes();
>                      //System.out.println("Animals = " + nlll.getLength());
>
>                      for (int k = 0; k < nlll.getLength()-1; k++)
>                      {
>                          Node chhh = nlll.item(k);
>                          System.out.println("NodeType 1"+
> chhh.getNodeType());
>                          if (chhh.getNodeType() == 1)
>                          {
>                              System.out.println("NodeType 1"+
> chhh.getNodeName());
>                              System.out.println("NodeType 1"
> +chhh.getFirstChild().getNodeValue());
>
> applicationArrayList.add(chhh.getFirstChild().getNodeValue());
>
>                          }
>
>                      }
>
>                  }
>
>
>              }
>
>
>          }
>
>      How can I skip  when i get null values in the xml??
>
>
>
>
>
> regards,
> ramu
>
>  Send instant messages to your online friends http://in.messenger.yahoo.com
>
>  Stay connected with your friends even when away from PC. Link:
> http://in.mobile.yahoo.com/new/messenger/


-- 
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.