I think you've misunderstood what nodes are involved. This XML:
<country>US</country>
... contains two nodes:
- The
country
element - The text node, with content of US
The element is not a text node, and the text node doesn't have an element name, because it's not an element. It's important to understand that these are different nodes. That's the source of all your confusion, I believe.
If you're currently looking at the text node, you could use node.getParentNode().getNodeName()
to get the element name. Or from the element node, you could call getTextContent()
.