header = new LinkedHashMap<String,Object>();
Element headerElement = (Element)doc.getElementsByTagName( "Header").item(0);
NodeList elementList = headerElement.getElementsByTagName( "*" );
for( int index =0; index < elementList.getLength(); index++ ){
Node element = elementList.item(index);
System.out.println( element.getChildNodes().item(0).getTextContent() ); // Statement A
System.out.println( element.getTextContent()); // Statement B
Both Statement A and Statement B are printing the same output.
What does it means, every node is a child node for itself??
And the input XML is
<Header>
<tag1>1</tag1>
<tag2>2</tag2>
<tag3>3</tag3>
<tag4>4</tag4>
</Header>
getTextContent()returns returns the text content of this node and its descendants.Statement A executed at
tag1returns the text node below (1)Statement B executed at the same place gets the child nodes of
tag1(a list with one text node), selects the first (only) text node and displays its text value.In this instance they are the same thing.