• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

null tags in incoming xml string

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My client has decided to introduce null tags in the incoming xml strings
while i parse the document with null tags and try to get the value it gives me a null pointer
eg:"
<SearchName><Last>kalidoss</Last><First/></SearchName>
if(search.getNodeName().equalsIgnoreCase("First"))
{
String first=search.getFirstChild().getNodeValue();
System.out.println("The value of first is"+first);
}
}
it goes into the if loop, but the node "search" is a null node
is there any way i can avoid this??? other than catching it in a try catch block for null pointers???
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The null value is coming from getFirstChild() since the node "First" doesnt' have any children.
How 'bout using plain Java if statement?

Why wouldn't that work?
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic