<parent>
<child1> value 1 </child1>
<child2> value 2 </child2>
<child3> value 3 </child3>
</parent>
What you are getting is the whitespace text node between the child1
and child2
elements.
You need to keep walking the siblings to skip over whitespace, comments, etc, to get the next element node:
Node child1 = elemNodeList.item(j);
Node sibling = child1.getNextSibling();
while (!(sibling instanceof Element) && sibling != null) {
sibling = sibling.getNextSibling();
}
System.out
.println(" Get the Name of the Next Sibling " + sibling.getNodeName());
System.out
.println(" Get the Value of the Next Sibling " + sibling.geTextContent());