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?
Using jdom2 : http://www.jdom.org/
import java.io.StringReader; import org.jdom2.input.SAXBuilder; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; String prettyXml = new XMLOutputter(Format.getPrettyFormat()). outputString(new SAXBuilder().build(new StringReader(uglyXml)));