title: jTidy - Pretty Printing without Head, Title Tags
body: <p>I am trying to use jTidy to pretty print on a HTML snippet that I have. So far I have done the following.</p>
  
  <pre><code>protected String prettyPrintHTML(String rawHTML) {
  
      Tidy tidy = new Tidy();
      tidy.setXHTML(true);
      tidy.setIndentContent(true);
      tidy.setPrintBodyOnly(true);
      tidy.setTidyMark(false);
  
      // Convert HTML to DOM
      Document htmlDOM = tidy.parseDOM(new ByteArrayInputStream(rawHTML.getBytes()), null);
  
      // Pretty Print
      OutputStream out = new ByteArrayOutputStream();
      tidy.pprint(htmlDOM, out);
  
      return out.toString();
  }
  </code></pre>
  
  <p>This works, but the output includes additional content such as &lt;html&gt;, &lt;head&gt;, &lt;title&gt; and &lt;body&gt; tags. </p>
  
  <p>For example, for input &lt;ul&gt;&lt;li&gt;sub1&lt;/li&gt;&lt;li&gt;sub2&lt;ul&gt;&lt;li&gt;sub21&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt; this gives,</p>
  
  <pre><code>line 1 column 59 - Warning: inserting missing 'title' element
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;title&gt;
      &lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;ul&gt;
        &lt;li&gt;
          sub1
        &lt;/li&gt;
        &lt;li&gt;
          sub2
          &lt;ul&gt;
            &lt;li&gt;
              sub21
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>After skimming through the API, I found the <code>setPrintBodyOnly</code> method (which I have used above), but still no luck. </p>
  
  <p>What am I missing here ? I tried Googling but so far all links lead to dead ends.</p>