Hi!
I'd like to present an easy, yet powerful approach to use the HTML
Tidy program from <http://tidy.sourceforge.net/> in ASP.NET. It is
similiar to
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/tchVSAddinEnablingHTMLTidy.asp>.
However, it is not implemented as a Visual Studio Add-in, but as a
response filter. This way, the complete HTML source is tidied,
including the output of web controls.
The VB.NET code can be downloaded from
<http://schneegans.de/temp/TidyFilter.vb.txt>. Furthermore, you need
the executable tidy.exe, which can be downloaded from
<http://tidy.int64.org/tidy-exe.zip>, and a configuration file
tidy.cfg. You should see reasonable results with
<http://schneegans.de/temp/tidy.cfg.txt>. Place both tidy.exe and
tidy.cfg in the root directory of your web application.
You call the filter by adding
Response.Filter = New TidyFilter(Response.Filter)
to your .aspx file(s). Page_Load seems to be the proper place to do
this.
Since Tidy is able to convert HTML to XHTML, you can use Tidy's output
to create an XmlDocument, by calling another filter:
Response.Filter = New TidyFilter(New XhtmlFilter(Response.Filter))
The XhtmlFilter class could apply an XSLT stylesheet to your page, add
arbitrary elements or attributes, or just change the attribute value
delimiter from " to '.
Feedback is greatly appreciated.
--
<http://schneegans.de/> · MVP FrontPage · <script></script> |