How do I make XhtmlTextWriter write a newline before an open tag immediately preceeded by a close tag?
<p>I'm using an XhtmlTextWriter to write out some Xtml along the following lines:</p>

<pre><code>XhtmlTextWriter writer = // init writer;
writer.WriteLineNoTabs(
    "&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"&gt;");
writer.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
writer.AddAttribute("xml:lang", "en");
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);

writer.RenderBeginTag(HtmlTextWriterTag.Title);
writer.Write("My Title");
writer.RenderEndTag(); // Title

writer.RenderEndTag(); // Head

writer.RenderBeginTag(HtmlTextWriterTag.Body);


writer.RenderBeginTag(HtmlTextWriterTag.H3);
writer.WriteLine("My Heading", userName);
writer.RenderEndTag(); // H3

writer.RenderBeginTag(HtmlTextWriterTag.H6);
writer.WriteLine("My Sub-heading");
writer.RenderEndTag(); // H6

writer.RenderBeginTag(HtmlTextWriterTag.Hr);
writer.RenderEndTag(); // Hr

writer.RenderBeginTag(HtmlTextWriterTag.P);
writer.WriteLine("Hello World.");
writer.RenderEndTag(); // P

writer.RenderEndTag(); // Body

writer.RenderEndTag(); // Html
</code></pre>

<p>What I get in the output is something like the following:</p>

<pre><code>&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" xml:lang="en"&gt;
    &lt;head&gt;
        &lt;title&gt;
            My Title
        &lt;/title&gt;
    &lt;/head&gt;&lt;body&gt;
        &lt;h3&gt;
            My Heading

        &lt;/h3&gt;&lt;h6&gt;
            My Sub-heading

        &lt;/h6&gt;&lt;hr /&gt;&lt;p&gt;Hello World.
        &lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>While this is valid Xhtml I was expecting a newline between tags like <code>&lt;/head&gt;</code> and <code>&lt;body&gt;</code>. I would make the resulting Xhtml easier to read, for one thing. </p>

<p>Is there a way I can get the XtmlTextWriter to do this? </p>

<p>I messed around a bit with overriding <code>RenderAfterTag</code> and similar, but since the lack of newline is only in the case of a close tag followed immediately by an open tag it was not immediately obvious how to implement it.</p>
