This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
    Bookmark Topic Watch 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • Mark post as helpful
  • send pies
  • Report post to moderator
The org.w3c.dom package contains an interface 'Node', which has (among others) methods getNodeName() and getNodeValue(). Now, there is often some unclarity regarding what these methods actually return for different types of Nodes...

The best resource for resolving the answer is the official javadoc for the Node interface: JavaDoc:org.w3c.dom.Node There's a table listing what the return value actually is for your particular Node type:

Attrname of attributevalue of attributenull
CDATASection" "content of the CDATA Sectionnull
Comment" "content of the commentnull
Document" "nullnull
DocumentFragment" "nullnull
DocumentTypedocument type namenullnull
Elementtag namenullNamedNodeMap
Entityentity namenullnull
EntityReferencename of entity referencednullnull
Notationnotation namenullnull
ProcessingInstructiontargetentire content excluding the targetnull
Text" "content of the text nodenull

Notice that the getNodeValue() method for an instance of org.w3c.dom.Element, "<elem>value</elem>" for example, does not return the value of its contents. Instead, you need to getChildNodes() and concatenate the values of the Text nodes (there may be more than one) in order to get the enclosing Element's value.

The following is a sample snippet returning the value (contents) of an Element node:

XmlFaq CategoryCodeSamples
I've never won anything before. Not even a tiny ad:
how do I do my own kindle-like thing - without amazon
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!