Setting the Attribute Value of a HtmlNode does not appear in the HtmlDocument.

html-agility-pack setattribute

Question

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?

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");

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

1
1
1/4/2011 1:47:00 AM

Accepted Answer

Actually it was a case of ProgrammerTooStupidException :(

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

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

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

Posting this reply to clear the name of HAP.

1
1/4/2011 1:17:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow