I have an HTML document stored in memory as an Linq-to-XML object tree. How can I serialize an XDocument as HTML, taking into account the idiosyncrasies of HTML?
For example, empty tags such as <br/>
should be serialized as <br>
, whereas an empty <div/>
should be serialized as <div></div>
.
HTML output is possible from an XSLT stylesheet, and XmlWriterSettings
has an OutputMethod
property which can be set to HTML - but the setter is internal
, for use by XSLT or Visual Studio, and I can't seem to find a way to serialize arbitrary XML as HTML.
So, short of using XSLT solely for the HTML output capability (i.e. doing something like running the document through an otherwise pointless chain of XDocument->XmlReader->via XSLT, to HTML), is there a way to serialize a .NET XDocument to HTML?