• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

getChildNodes() method returning null in Servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,



I�m getting a peculiar problem in a java servlet program which I developed. I�ll explain it now.

I developed an application with w3c.dom parser (for parsing xml information) in java. When I execute my program as a stand alone java program, it is getting the results properly. But when I tried to integrate into a Servlet, it is not getting the proper results. Mainly the following statement (number 2) is getting problem,

1. Element root = doc.getDocumentElement();

2. String response = root.getChildNodes().toString();

In Java servets, the string variable �response� value is getting null. But if I execute the same as a normal (i.e. stand alone) java program then it is getting the results properly. I�m not getting the reason why it is getting null when I execute as a servlet program. If any body can help me in solving this then it will be a great help for me.


Thanks in advance.
[ December 17, 2005: Message edited by: Ravi Sengodan ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way for the response variable to end up with null is if an exception that you are not catching and displaying occurs and the code line is never executed. Since even with an empty root element you should get an empty NodeList, I bet this is what is happening.
Bill
[ December 17, 2005: Message edited by: William Brogden ]
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using different versions of the XML software there. When you call toString() on a Node, some DOM implementations return the XML representation of the Node, and others return what the nodeValue() method returns. So when you see "null", you are using one of the latter implementations.

(Note from the API documentation for Node that if the Node is an Element, then nodeValue() returns null. That doesn't mean the Element is null.)

The way to make this consistent is to stop using toString() to display Nodes from a DOM, since it's undefined how toString() works on a Node and implementers are free to choose different representations.
 
Ravi Sengodan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks William and Paul.,

Now it is working fine. The probelem has happened because of the xml api incompatibility. Now i have corrected it....Thanks for information....

thanks,
Ravi
[ December 21, 2005: Message edited by: Ravi Sengodan ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic