incorrect markup in HtmlAgilityPack

c# html html-agility-pack

Question

I am using the HtmlAgilityPack from codeplex. When I pass a simple html string into it and then get the resulting html back, it cuts off tags.

Example:

string html = "<select><option>test</option></select>";
HtmlDocument document = new HtmlDocument();
document.LoadHtml(html);

var result = d.DocumentNode.OuterHtml;

// result gives me:
<select><option>test</select>

So the closing tag for the option is missing. Am I missing a setting or using this wrong?

1
1
9/16/2011 4:00:49 PM

Accepted Answer

I fixed this by commenting out line 92 of HtmlNode.cs in the source, compiled and it worked like a charm.

ElementsFlags.Add("option", HtmlElementFlag.Empty); // comment this out

Found the answer on this question

4
5/23/2017 12:15:22 PM

Popular Answer

In HTML the tag has no end tag.

In XHTML the tag must be properly closed.

http://www.w3schools.com/tags/tag_option.asp

"There is also no adherence to XHTML or XML" - HTML Agility Pack.

This could be why? My guess is that if the tag is optional, the Agility Pack will leave it off. Hope this helps!



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow