aspose file tools*
The moose likes XML and Related Technologies and the fly likes a ReadXMLFile Servlet works without my expectation... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "a ReadXMLFile Servlet works without my expectation..." Watch "a ReadXMLFile Servlet works without my expectation..." New topic
Author

a ReadXMLFile Servlet works without my expectation...

Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124

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...


a beginner in java
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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".


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
prat narang
Greenhorn

Joined: Oct 27, 2003
Posts: 10
hi,
just change u'r recursiveGetNodes function like i've done in bold and u'll get the desired output.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a ReadXMLFile Servlet works without my expectation...
 
Similar Threads
help!Urgent,my assignment.....
session object = null?
Can anyone help?I still can't append records in xml...
Why I can't retrieve records stored in a XMLFile correctly?
xml JAVA