Reputation: 59
So I have an application that collects the header and footer sections of an HTML document and inserts them into a preexisting web page. Both sections are already wrapped in div tags so the content within the boxes shouldn't have html/body tags.
That being said, I'd like to check for tags that aren't closed and programmatically close them. I'm very new to Html Agility Pack and I'm not sure how to accomplish what I want. Here is the code that I have been able to infer based upon Google searches.
private bool RepairHtml(string htmlText)
{
var htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(htmlText);
var parseErrors = htmlDoc.ParseErrors;
if (parseErrors != null)
{
foreach (var htmlParseError in parseErrors)
{
switch (htmlParseError.Code)
{
case: HtmlParseErrorCode.TagNotClosed:
// Not sure what to do here
break;
}
}
}
}
How do I select the tag that generated an error and close it?
Thanks in advance for your help!
Upvotes: 0
Views: 3434