HTML Agility Pack:设置HtmlNode的属性值未反映在HtmlDocument中 [英] Html Agility Pack: Setting an HtmlNode's Attribute Value isn't reflected in the HtmlDocument

查看:75
本文介绍了HTML Agility Pack:设置HtmlNode的属性值未反映在HtmlDocument中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Html Agility Pack, when I set an attribute of an HtmlNode, should I see this in the HtmlDocument from which the node was selected?

可以说htmlDocument是一个HtmlDocument.因此,简化的代码如下所示:

Lets say that htmlDocument is an HtmlDocument. So the simplified code looks like this:

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

现在,我看到了节点更改的类属性,但是我没有看到此更改反映在htmlDocument的html中.

Now, I see the class attribte of node change, but I don't see this change reflected in the htmlDocument's html.

推荐答案

实际上是ProgrammerTooStupidException的一种情况:(

Actually it was a case of ProgrammerTooStupidException :(

我使用了MyHtmlPage类,该类具有Html属性和DocumentProperty.

I used a MyHtmlPage class, with an Html property and an DocumentProperty.

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

现在,很自然地,DocumentNode对_html值没有影响.

Now, of coourse manipulation the DocumentNode had no effect on the _html value.

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

Posting this reply to clear the name of HAP.

这篇关于HTML Agility Pack:设置HtmlNode的属性值未反映在HtmlDocument中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆