Reputation: 852
I would like to check if a given string has a correct html syntax. I don't know which html elements should be inside, the only one thing I know is that string should be a correct html expression.
Anyone has an idea how to check it in C#?
Upvotes: 22
Views: 17069
Reputation: 3044
You can use Html Agility Pack : http://html-agility-pack.net/?z=codeplex
string html = "<span>Hello world</sspan>";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
if (doc.ParseErrors.Count() > 0)
{
//Invalid HTML
}
Upvotes: 36