I have a XML document (read from a db) that has whitespace/newline characters when I load it in to a Document the Node Attribute is missing the whitespace/newline characters..
Is there a way to keep the whitespace/newline information?
Sample
<Message>
<Header format="qwe" standard="123.456">
<Version value="2"/>
<G1>
<Originator value="google"/>
</G1>
</Header>
<Body format="xyz" standard="abc" type="123">
<Comments value="uuuuuuuuuuuuuuuuuuu
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ttttttttttttttttt
44444
3333
22
"/>
</Body>
</Message>
code:
String parseXML = new String(this.messageXML);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document documentMessage = builder.parse(new InputSource(new StringReader(parseXML)));
NodeList bodyNodes = documentMessage.getElementsByTagName("Comments");
if (bodyNodes.getLength() > 0) {
System.out.println("Nodelist has something.." + bodyNodes.getLength());
for(int nodeCount = 0; nodeCount < bodyNodes.getLength(); nodeCount++) {
Node localNode = bodyNodes.item(nodeCount);
System.out.println("localNodeValue... " + localNode.getAttributes().getNamedItem("value").getTextContent());
}
}