How do I check to see if my XML tag does not hold a value?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Noel_Prevost
Posted On:   Thursday, April 4, 2002 06:12 AM

I am parsing an XML document that looks like the small sample below. Special Action Save Part Information CAGE Code I can easily read in the first part of this XML. However, when I get to the node for CAGE Code, I get an error when I try to .getNodeValue(). I have even tried to read the node name with .getNodeName() but it returns value so my code still tries to get the value which bombs it out. How do I check for the Node not having a text value? My code to handle this which doesn't work properly is below. if (fn.getFirstChild().getNodeValue().equals("PROPERTY")) { /   More>>

I am parsing an XML document that looks like the small sample below.



			


Special Action

Save Part Information





CAGE Code









I can easily read in the first part of this XML. However, when I get to the node for CAGE Code, I get an error when I try to .getNodeValue(). I have even tried to read the node name with .getNodeName() but it returns value so my code still tries to get the value which bombs it out. How do I check for the Node not having a text value? My code to handle this which doesn't work properly is below.



if (fn.getFirstChild().getNodeValue().equals("PROPERTY"))

{ //the node value matches what we are looking for



fieldName = tnl.item(1);

if (fieldName.getNodeName().equals("value")) {

returnVal = tnl.item(1).getFirstChild().getNodeValue();

}

else { returnVal = "NULL"; }


}//end if




The code actually works but the else condition is never reached. Any help would be greatly appreciated.


thanks

   <<Less

Re: How do I check to see if my XML tag does not hold a value?

Posted By:   Noel_Prevost  
Posted On:   Friday, May 3, 2002 12:00 PM

I ended up handling this by catching the null pointer exception that was being thrown.
About | Sitemap | Contact