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] skipping the null node values in a DOM Tree

[ Lists Home | Date Index | Thread Index ]
  • To: Anthony Ettinger <aettinger@sdsualumni.org>
  • Subject: Re: [xml-dev] skipping the null node values in a DOM Tree
  • From: Seetha Rama Krishna <ram_kurra@yahoo.co.in>
  • Date: Thu, 8 Jun 2006 06:52:05 +0100 (BST)
  • Cc: xml-dev@lists.xml.org
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.in; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=oZ57CfyMD/J6hQ7WqK5o82umzQGx1jgUC8LKAmWmENBoWnWk2LhbX6DQGlsD60LOlBf3BZT09rB+S4OCnhHDHXq0cOJbkNPAfewu6gADL8C34JRn6IduGTxPbD9v9O5Kus4dSvy2bBtSUVy6qGsX5fZF01W9mH/t55n+rD/o8i0= ;
  • In-reply-to: <3fc6b2fb0606072235k5c120428wd7b41294b9410617@mail.gmail.com>

Hi Anthony,
    Thanxs 4 u r reply. I tried with u r solution like
if (!chhh.getFirstChild().getNodeValue().equals(null))
{
            System.out.println("value exists:"+chhh.getFirstChild().getNodeValue());
 }
 else
{
            System.out.println("value does not exist.");
 }
      But here the problem is chhh.getFirstChild().getNodeValue() is returing a string.

        Before checking for null value , the chhh.getFirstChild().getNodeValue() is giving null values and I am getting null pointer xception.




Anthony Ettinger <aettinger@sdsualumni.org> wrote:
I'm not a java programmer, but I would guess it's like most other languages I've used, look at the spec and see what it returns for getNodeValue();

if (chhh.getFirstChild().getNodeValue()) {

should be similar to this... (I use Perl here to declare a value with "my", but it shouldn't make any difference):

if (my $value = chhh.getFirstChild().getNodeValue()) {
        print "value is: $value";
} else {
       print "value is undefined :(";
}



if $value is not defined, it would not go into the block.

However, it's up to you, but you shouldn't have to assign it to a variable just to check if the function returns a value, thus if (test) should work:

if (chhh.getFirstChild().getNodeValue()) {
           System.out.println("value exists:"+chhh.getFirstChild().getNodeValue());
} else {
           System.out.println("value does not exist.");
}


On 6/7/06, Seetha Rama Krishna < ram_kurra@yahoo.co.in> wrote:
it there any method to check whether that node has node value/ not . If not how can i do this one??


Anthony Ettinger <aettinger@sdsualumni.org> wrote:
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 wrote:
> Hi,
> I am having an xml file like the following
>
>
> 4
> CLIENTDEMO

>
>
>
> I had written java code to iterate thru this xml and retrieve the
> values . when the element 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



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



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/





 

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

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