HtmlAgilityPack close form tag automatically

.net html html-agility-pack

Question

I am tring to parse an html file with this code:

<div><form>...</div>...</form>

the problem is that the HtmlAgilityPack automatically close the form tag before the div ending tag: <div><form>...</form></div>...</form> so when I parse the form some of the form elements are missing. (I get only the elements befor the automatically added tag)

I already tried:

htmlDoc.OptionFixNestedTags = false;
htmlDoc.OptionAutoCloseOnEnd = false;
htmlDoc.OptionCheckSyntax = false;
HtmlNode.ElementsFlags.Remove("form");
HtmlNode.ElementsFlags.Add("form", HtmlElementFlag.CanOverlap);
HtmlNode.ElementsFlags.Add("div", HtmlElementFlag.CanOverlap);

But nothing helps!

thanks for you help!

Popular Answer

The following seems to work for me:

HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form");

_document = new HtmlDocument();
_document.OptionAutoCloseOnEnd = true;
_document.LoadHtml(content);



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why