Skip to content Skip to sidebar Skip to footer

C# Html From Webbrowser To Valid Xhtml

So, we are using a webBrowser control in edit mode, to allow people to enter text, and then take that text and send it out to the server for everyone to see. IE, it's an HTML inpu

Solution 1:

Would reccomend using either something like TinyMCE or HtmlAgilityPack (available as a Nuget package or from codeplex).

TinyMCE allows users to perform a rich text edit with appropriate formatting controls, and will output the resultant Html.

HtmlAgilityPAck on the other hand is a library that will allow you to pass in the HtmlStream generated by your method, and output this as a valid Xhtml stream.

Rough example for working with this in the HtmlAgilityPAck as below:

var sb = new StringBuilder(); 
var stringWriter = new StringWriter(sb);

string input = "<html><body><p>This is some test test<ul><li>item 1<li>item2<</ul></body>";

var test = new HtmlAgilityPack.HtmlDocument();
test.LoadHtml(input);
test.OptionOutputAsXml = true;
test.OptionCheckSyntax = true;
test.OptionFixNestedTags = true;

test.Save(stringWriter);

Console.WriteLine(sb.ToString());

Post a Comment for "C# Html From Webbrowser To Valid Xhtml"