HtmlAgilityPack invalid markup

空扰寡人 提交于 2019-12-02 09:01:39

问题


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:


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




回答2:


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!



来源:https://stackoverflow.com/questions/7447461/htmlagilitypack-invalid-markup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!