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 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

nodeTypenodeNamenodeValueattributes
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
 
    Bookmark Topic Watch Topic
  • New Topic