正しくHTMLをフォーマットするTidy.netを使用してみてください(HtmlAgilityPack名前空間を使用して忘れないでください)。 tidy.net
var document = new Tidy();
var messageCollection = new TidyMessageCollection();
document.Options.DocType = DocType.Omit;
document.Options.Xhtml = true;
document.Options.CharEncoding = CharEncoding.UTF8;
document.Options.LogicalEmphasis = true;
document.Options.MakeClean = false;
document.Options.QuoteNbsp = false;
document.Options.SmartIndent = false;
document.Options.IndentContent = false;
document.Options.TidyMark = false;
document.Options.DropFontTags = false;
document.Options.QuoteAmpersand = true;
document.Options.DropEmptyParas = true;
using (var input = new MemoryStream())
{
using (var output = new MemoryStream())
{
byte[] array = Encoding.UTF8.GetBytes(xmlResult);
input.Write(array, 0, array.Length);
input.Position = 0;
document.Parse(input, output, messageCollection);
return Encoding.UTF8.GetString(output.ToArray());
}
}
ユーザーがページにHTMLを追加することができたときに、クロスサイドスクリプティングの注意する必要があります。 この投稿を見てSanitising HTML with C# and Tidy