Home All Groups Group Topic Archive Search About
Author
13 Dec 2006 10:21 AM
Martin Odhelius
Hello,

Does anybody here have any example code for Tidy.Net
(http://sourceforge.net/projects/tidynet/) ?

I can't find one single example. I try to convert a html-string to well
formed xhtml, but the only output I get is /r/n

Any help would be appreciated :)

Best Regards
Martin

Author
17 Dec 2006 1:29 AM
Martin Odhelius
It wasn't actually that hard to figure it out ;) I just forgot to reset
the position of the stream, therefor the "/r/n"-result ;) Here is a
code example if anyone else needs one in the future:

Tidy tidy = new Tidy();

/* Set the options you want */
tidy.Options.DocType = DocType.Strict;
tidy.Options.DropFontTags = true;
tidy.Options.LogicalEmphasis = true;
tidy.Options.Xhtml = true;
tidy.Options.XmlOut = true;
tidy.Options.MakeClean = true;
tidy.Options.TidyMark = false;

/* Declare the parameters that is needed */
TidyMessageCollection tmc = new TidyMessageCollection();
MemoryStream input    = new MemoryStream();
MemoryStream output    = new MemoryStream();

byte[] byteArray = Encoding.UTF8.GetBytes("Put your HTML here...");
input.Write(byteArray, 0 , byteArray.Length);
input.Position = 0;
tidy.Parse(input, output, tmc);

string result = Encoding.UTF8.GetString(output.ToArray());

Bookmark and Share