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:
nodeType | nodeName | nodeValue | attributes |
Attr | name of attribute | value of attribute | null |
CDATASection | " " | content of the CDATA Section | null |
Comment | " " | content of the comment | null |
Document | " " | null | null |
DocumentFragment | " " | null | null |
DocumentType | document type name | null | null |
Element | tag name | null | NamedNodeMap |
Entity | entity name | null | null |
EntityReference | name of entity referenced | null | null |
Notation | notation name | null | null |
ProcessingInstruction | target | entire content excluding the target | null |
Text | " " | content of the text node | null |
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