I use hmml agility pack to read the contents of my html document into a string, etc. After that, I would like to remove the certian elements in this content by their class, however I am encountering a problem.
My HTML is as follows:
<div id="wrapper"> <div class="maincolumn" > <div class="breadCrumbContainer"> <div class="breadCrumbs"> </div> </div> <div class="seo_list"> <div class="seo_head">Header</div> </div> Content goes here... </div>
Now I used the xpath selector to get all the content inside and used the InnerHtml property as follows:
node = doc.DocumentNode.SelectSingleNode("//div[@id='wrapper']"); if (node != null) { pageContent = node.InnerHtml; }
From now on, I would like to remove the div with class "breadCrumbContainer", however when using the code below I get the error: "Node" "not found in collection"
node = doc.DocumentNode.SelectSingleNode("//div[@id='wrapper']"); node = node.RemoveChild(node.SelectSingleNode("//div[@class='breadCrumbContainer']")); if (node != null) { pageContent = node.InnerHtml; }
Can someone shed some light on this, please? I am new to Xpath and really new to the HtmlAgility library.
Thanks,
Dave
Dave
source share