title: How to pretty print XML from Java?
body: <p>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?</p>
  
  <pre><code>String unformattedXml = "&lt;tag&gt;&lt;nested&gt;hello&lt;/nested&gt;&lt;/tag&gt;";
  String formattedXml = new [UnknownClass]().format(unformattedXml);
  </code></pre>
  
  <p>Note: My input is a <strong>String</strong>. My output is a <strong>String</strong>. </p>
  
  <p>(Basic) mock result:</p>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
    &lt;tag&gt;
      &lt;nested&gt;hello&lt;/nested&gt;
    &lt;/tag&gt;
  &lt;/root&gt;
  </code></pre>