This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a ReadXMLFile Servlet works without my expectation...

 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

my servlet program

the result is:

But I want to read all ChildNode's NodeValue instead of null.
for example,<author>Michael</author>,so The child node is : author and the node value is: "Michael" instead of "null"...
How can I achieve this?
Thanks in advance...
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you take a look at org.w3c.dom.Node class' javadocs, you'll find a nice table summarizing what getNodeName() and getNodeValue() will return for different types of nodes.
For elements, getNodeValue() always returns null. That's because they don't have a value, but child elements. In your case, the "author" element has one or more child elements of type "#text"... You need to getChildNodes() and append their values together in order to get "Michael".
 
prat narang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
just change u'r recursiveGetNodes function like i've done in bold and u'll get the desired output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic