I want to make sure that the HTML that I generate using the HtmlAgility package is valid HTML5.
For example, the following creates an empty HTML5 document. I will have other, similary functions that will create more complex documents. I want the tests to verify that I don't blame anything, and the resulting HTML is well-formed and valid.
public static String CreateEmptyHtmlDoc() { var hd = new HtmlDocument(); var doctype = hd.DocumentNode.SelectSingleNode("/comment()[starts-with(.,'<!DOCTYPE')]"); if (doctype == null) doctype = hd.DocumentNode.PrependChild(hd.CreateComment()); doctype.InnerHtml = ""; hd.DocumentNode.AppendChild( HtmlNode.CreateNode( "<HTML><HEAD><META CHARSET=\"UTF-8\"><TITLE></TITLE></HEAD><BODY></BODY></HTML>")); return hd.DocumentNode.OuterHtml; }
How can I create an "html5 validator" using the HtmlAgility Pack, where I could do something like this:
Assert.IsTrue(IsValidHtml5(CreateEmptyHtmlDoc()));
Thanks.
tig source share