本文介绍了HtmlAgilityPack无效标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从codeplex使用HtmlAgilityPack。
当我将一个简单的html字符串传递给它,然后得到返回的html时,
将切断标签。

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.

示例:

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?

推荐答案

我通过在源代码中注释掉HtmlNode.cs的第92行,编译后就像一个魅力。

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

这篇关于HtmlAgilityPack无效标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!