Microsoft : SgmlReader. ( ) tidy html.
, Html xml:
public static string HtmlToXHtml(string input)
{
using (var sr = new StringReader(input))
{
var hr = new SgmlReader(sr);
hr.InputStream = sr;
hr.DocType = "HTML";
var output = new StringBuilder();
var hw = new XmlTextWriter(new StringWriter(output));
hr.Read();
while (!hr.EOF)
{
hw.WriteNode(hr, true);
}
return output.ToString();
}
}
You can simply update user input after the postback. In more complex scenarios (the need to switch between wysiwyg and Html modes) you may need a little Ajax to convert the html string to xhtml behind the curtain before showing the html source in the text box.
source
share