I have a Java application that fetches an xml file from a website which has a multi-line text-node like this:
<root>
<node>info</node>
<mlnode>some
multi
line
text</mlnode>
</root>
My code currently looks like this:
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
NodeList nList = doc.getElementsByTagName("mlnode");
Node nNode = nList.item(0);
System.out.println(nNode.getTextContent());
Sadly, this code puts my multiline content into one line: somemultilinetext
. I'd like to preserve the linebreaks. And I'd like to have the linebreaks preserved on all operating systems (primarily windows and linux).
How do I do that?
Edit: This question is NOT about correct indenting. It's only about keeping the linebreaks in the contents of the nodes. It's important to keep the linebreaks where they were because the content of that node is part of a configuration file and has to be separated by linebreaks.
I don't care about correct indenting (and if I did: I know there are enough sources on SO and other forums that explain how to correctly indent).