reading the answer here : Normalization in DOM parsing with java - how does it work?
I understand that the normalization will remove empty adjacent text nodes, I tried the following xml :
<company>hello
wor
ld
</company>
with the following code :
try {
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = dBuilder.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
System.out.println(doc.getDocumentElement().getChildNodes().getLength());
System.out.println(doc.getDocumentElement().getChildNodes().item(0).getTextContent());
} catch (Exception e) {
e.printStackTrace();
}
I always get 1 child node for the element "company" even without normalize. the result is :
Root element :company
1
hello
wor
ld
so what is wrong here ? can anyone explain ? shouldn't I get hello world in one line.