1

在 Html Agility Pack 中,当我设置 HtmlNode 的属性时,我应该在从中选择节点的 HtmlDocument 中看到这个吗?

假设 htmlDocument 是一个 HtmlDocument。所以简化的代码如下所示:

HtmlNode documentNode = htmlDocument.DocumentNode;
HtmlNodeCollection nodeCollection = documentNode.SelectNodes(someXPath);
foreach(var node in nodeCollection)
   if(SomeCondition(node))
       node.SetAttributeValue("class","something");

现在,我看到节点的类属性发生了变化,但我没有看到 htmlDocument 的 html 中反映了这种变化。

4

1 回答 1

1

实际上这是 ProgrammerTooStupidException 的一个案例 :(

我使用了一个带有 Html 属性和 DocumentProperty 的 MyHtmlPage 类。

_html = theHtml;
_htmlDocument = new HtmlDocument();
HtmlDocument.LoadHtml(theHtml)l
_documentNode = HtmlDocument.DocumentNode;

现在,当然操作 DocumentNode 对 _html 值没有影响。

发布此回复以清除 HAP 的名称。

于 2011-01-04T13:17:17.190 回答