开发者

Using HTML Tidy in Visual C++ 2010 Windows Forms project

I am using VC++ 2010 Express and I am attempting to include HTML Tidy to perform cleanup on HTML code strings. What I want to do is process the HTML as a string (NOT from a file) and save the processed cleaned HTML to a string (NOT to a file). The project is a C++ Windows forms project, the compiler is /CLR.

I have attempted, more times than I care to admit, to attach Tidy to my project in various ways. I have failed in every attempt and I'm just not sure where to go from here. The most promising was a .NET wrapper called TidyManaged, but I could not find any documentation to explain how to use it with C++ (it appears to have been meant for C#). The various C++ wrappers are not working for me at all. It seems the documentation is extremely lacking on how to make them work.

Also I am prepared to accept a solution that does not use tidy at all, but some other equivalent HTML cleanup tool. I am concerned about the age of Tidy (August, 2000) and whether it is still effective for today's newer XHTML standards.

Also if it's possible, I am willing to incorporate a C library into my code directly without relying on a DLL, but I have no knowledge on how to make this work or even if it can work.

Any suggestions on how to go about this would be greatly appreciated, keeping in mind that this is HTML we are talking about here (often times malformed HT开发者_JS百科ML and XHTML) and NOT XML.

Thanks in advance!

PS - I am new to C++ :/


It's been almost 48 hours struggling with this problem. Solution discovered! Here it is...

Using the very simple .NET wrapper from here http://www.codeproject.com/KB/cs/ZetaHtmlTidy.aspx converted the VC project to VC++ 2010 ok and compiled as a DLL ok. Below is the code I used to call it:

System::String^ TidyMyHTML(String^ MyHTMLString)
{
    using namespace ZetaHtmlTidy;
    HtmlTidy tidy;
    String^ s = tidy.CleanHtml( MyHTMLString, HtmlTidyOptions::ConvertToXhtml );
    return s;
}

Hopefully this post will spare someone else from going through the same thing.

EDIT:

Taking this a step further I was able to convert the VC++ 2008 project files from the tidy source attached to the wrapper and upgrade them to VC++ 2010 project files. I was then able to compile the tidy project (separate from his wrapper class project) into libtidy.lib static libraries (both release and debug). I was then able to incorporate his wrapper class into my application and point to the include and lib files. The end result was exactly what I wanted, a solution that incorporates tidy into my application without needing to have a dll dependency. This whole experience has accelerated my learning curve for attaching C libraries to my C++ applications.

Thanks for the suggestions, and I hope someone finds this post useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜