Click here to Skip to main content
15,123,819 members
Articles / Operating Systems / Windows
Posted 12 Jan 2007


28 bookmarked

A managed wrapper for the HTML Tidy library

Rate me:
Please Sign up or sign in to vote.
4.83/5 (17 votes)
12 Jan 2007CPOL2 min read
A managed C++ for a small part of the HTML Tidy C library

(For the latest changes, please see the history section at the end of the article)


This is a small library in its initial creation state to provide a native .NET way in accessing the functions of the HTML Tidy library.

HTML Tidy is an open source C library for checking and generating clean XHTML/HTML. In other words: You can throw a misformatted HTML to the library and it will do its best to repair the errors and clean unnecessary items/tags from the HTML.

The Library

There already does exist a way to access the library from .NET, namely through the ATL wrapper of Charles Reitzel (SourceForge CVS repository of the sources here). But you need to register the COM ActiveX control first.

To get rid of this registration limitation, I created a C++/CLI wrapper of the original C library of HTML Tidy. This wrapper is a normal library that you can use in your .NET applications by simply adding a reference to the library.

Please note that my created library currently does not deserve to be called "library", because it really just consists of one single function until now.

The reason why I still do publish it here and now is that I want to provide the basic idea as early as possible to anyone being in the same situation than me (by needing a .NET wrapper for HTML Tidy). It's rather ease to take my library as a starting point and add the required functions you need. I did the core work, you simply add the functions you like.

Of course I gradually will add more functions to the library, as my requirements grow. And I also do encourage you to enhance it by yourself and send me your code so that I can include it.

The underlying C library

It was a pleasure to compile the original HTML Tidy C library. After first starting the provided Visual Studio .NET project file, compiled it for debug and release, received no errors, no warnings. Amazing! I never had such a seamless experience with compiling foreign C/C++ libraries.

Using my .NET library

The library currently has one function to call:

public string CleanHtml( string html );

Simply pass a string and get a cleaned up string back. Easy, isn't it?

An example usage could be:

using ( HtmlTidy tidy = new HtmlTidy() )
  string html =
        <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-16"">
        <p>Hello, <b><i>With German</b></i>: ÄÖÜ. Some Chinese: 讪.</p>

  string s = tidy.CleanHtml(
    HtmlTidyOptions.ConvertToXhtml );

  Console.WriteLine( s );

As you see, simply pass the string to the function. There is an overload with one option (currently, will be enhanced in the future, too).


In order to redistribute the library, please ensure that the Microsoft CRT runtime DLLs "msvcr80.dll", "msvcm80.dll" and "msvcp80.dll" are also being distributed. The libraries are usually being found in the folder "C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT".


  • 2007-01-14
    Added the section about redistributing the CRT library.
  • 2007-01-12
    First version published.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.

Some cool, free software from us:

Deutschsprachiges Forum zu Elektromobilität und Tesla  
Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email

Comments and Discussions

Questionfine Job Pin
yves3143-May-13 0:28
Memberyves3143-May-13 0:28 
GeneralTargeting 64-bit Pin
Nick Higgs24-Aug-07 0:56
MemberNick Higgs24-Aug-07 0:56 
GeneralThe dll cannot run in ASP.NET Medium trust application Pin
tsandl13-Mar-07 11:37
Membertsandl13-Mar-07 11:37 
GeneralRe: The dll cannot run in ASP.NET Medium trust application Pin
Uwe Keim13-Mar-07 20:22
sitebuilderUwe Keim13-Mar-07 20:22 
GeneralRe: The dll cannot run in ASP.NET Medium trust application Pin
tsandl13-Mar-07 20:52
Membertsandl13-Mar-07 20:52 
GeneralRe: The dll cannot run in ASP.NET Medium trust application Pin
Uwe Keim13-Mar-07 21:28
sitebuilderUwe Keim13-Mar-07 21:28 
GeneralRe: The dll cannot run in ASP.NET Medium trust application Pin
tsandl14-Mar-07 10:28
Membertsandl14-Mar-07 10:28 
GeneralRe: The dll cannot run in ASP.NET Medium trust application Pin
Thomas Haller2-Jul-13 4:14
MemberThomas Haller2-Jul-13 4:14 
GeneralBug Pin
mike_mmmm1-Mar-07 4:22
Membermike_mmmm1-Mar-07 4:22 
GeneralGreat tool! Pin
Koen_V28-Feb-07 22:39
MemberKoen_V28-Feb-07 22:39 
GeneralHave a look at tidyfornet Pin
Frederik198421-Feb-07 10:50
MemberFrederik198421-Feb-07 10:50 
GeneralRe: Have a look at tidyfornet Pin
Uwe Keim21-Feb-07 19:17
sitebuilderUwe Keim21-Feb-07 19:17 
GeneralRe: Have a look at tidyfornet Pin
mike_mmmm1-Mar-07 3:39
Membermike_mmmm1-Mar-07 3:39 
Generalbug - with sample file Pin
mike_mmmm17-Feb-07 16:04
Membermike_mmmm17-Feb-07 16:04 
GeneralRe: bug - with sample file Pin
Uwe Keim17-Feb-07 20:30
sitebuilderUwe Keim17-Feb-07 20:30 
GeneralRe: bug - with sample file Pin
mike_mmmm17-Feb-07 22:38
Membermike_mmmm17-Feb-07 22:38 
GeneralRe: bug - with sample file Pin
mike_mmmm17-Feb-07 22:40
Membermike_mmmm17-Feb-07 22:40 
GeneralHe does it again... Pin
Chris Maunder13-Feb-07 19:40
cofounderChris Maunder13-Feb-07 19:40 
GeneralRe: He does it again... Pin
Uwe Keim13-Feb-07 20:05
sitebuilderUwe Keim13-Feb-07 20:05 
GeneralNice job Pin
Clickok13-Feb-07 16:03
MemberClickok13-Feb-07 16:03 
GeneralRe: Nice job Pin
Uwe Keim13-Feb-07 19:13
sitebuilderUwe Keim13-Feb-07 19:13 
Generalbig problem with tidy Pin
mike_mmmm10-Feb-07 20:11
Membermike_mmmm10-Feb-07 20:11 
GeneralRe: big problem with tidy Pin
mike_mmmm10-Feb-07 20:15
Membermike_mmmm10-Feb-07 20:15 
GeneralRe: big problem with tidy Pin
Uwe Keim10-Feb-07 21:17
sitebuilderUwe Keim10-Feb-07 21:17 
GeneralRe: big problem with tidy Pin
Michael Sandrock21-Jun-07 18:03
MemberMichael Sandrock21-Jun-07 18:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.