I think you misunderstood which nodes are involved. This XML:
<country>US</country>
... contains two nodes:
country element- Text node, with US content
The element is not node text, and node text does not have an element name, because it is not an element. It is important to understand that these are different nodes. I believe that the source of all your confusion.
If you are viewing node text, you can use node.getParentNode().getNodeName() to get the name of the element. Or from a node element, you can call getTextContent() .
source share