I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this?
In case you do not need indentation that much but a few line breaks, it could be sufficient to simply regex...
String leastPrettifiedXml = uglyXml.replaceAll("><", ">\n<");
The code is nice, not the result because of missing indentation.
(For solutions with indentation, see other answers.)