title: Simple way to return formatted XML output in JSP document (JSPX)
body: <p>This was a problem when I tried to switch to XML-based JSP over 15 years ago, and it looks like it's still a problem.</p>
  
  <p>Using Tomcat 9, if I have a simple JSP page, the output is nicely formatted.</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=UTF-8" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en-US"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"/&gt;
    &lt;title&gt;Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Example&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The output looks pretty much the same as the source. But if I use a JSP document (JSPX):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.3"&gt;
  &lt;jsp:directive.page contentType="text/html; charset=UTF-8" /&gt;
  &lt;jsp:text&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/jsp:text&gt;
  &lt;html lang="en-US"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"/&gt;
    &lt;title&gt;Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Example&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;/jsp:root&gt;
  </code></pre>
  
  <p>Then the output just becomes one long line:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;&lt;html lang="en-US"&gt;&lt;head&gt;&lt;meta charset="UTF-8"/&gt;&lt;title&gt;Example&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Example&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Yes, I understand the reasons behind this: parsing to the XML document model, manipulating the tree, reserializing, etc. But as a practical matter: it's ugly, I don't like it, and probably nobody likes it. What's the easiest, most practical way to get some reasonable line breaks and indention in the output?</p>
  
  <p>The fact that the browser doesn't care is beside the point. As developers we have to work with this. This is ugly and gets in the way. (Yes, I know probably nobody uses JSPX or even JSP, but I thought I'd ask anyway.)</p>