在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中。
實際上這是ProgrammerTooStupidException的一個案例:(
我使用了MyHtmlPage類,帶有Html屬性和DocumentProperty。
_html = theHtml;
_htmlDocument = new HtmlDocument();
HtmlDocument.LoadHtml(theHtml)l
_documentNode = HtmlDocument.DocumentNode;
現在,在使用Coourse操作時,DocumentNode對_html值沒有影響。
發布此回復以清除HAP的名稱。