How to use HTMLAgilityPack AppendNode?

You have a real headache at this point on Friday! I am trying to add an HtmlNode to another using InsertAfter (). I see a refChild node with breadcrumbs identifier when I paste it into the console but keep getting the following error:

System.ArgumentOutOfRangeException: Node "<div id="breadcrumb"></div>" was not f
ound in the collection
Parameter name: node
   at HtmlAgilityPack.HtmlNodeCollection.get_Item(HtmlNode node)
   at HtmlAgilityPack.HtmlNode.InsertAfter(HtmlNode newChild, HtmlNode refChild)

   at MyHome.Tasks.Tasks.DownloadandStoreContent(KeyValueP
air`2 urlPair, String filePath, HtmlNode HtmlWrapper) in C:\Users\denis\Document
s\Visual Studio 2008\Websites\MyHomeV2\MyHome.Tasks\Tasks.cs:line 81
   at MyHome.Tasks.Tasks.GenerateContent(String scrape
sSwitch, String filePath) in C:\Users\denis\Documents\Visual Studio 2008\Website
s\MyHomeV2\MyHome.Tasks\Tasks.cs:line 27
   at MyHome.Tasks.Program.Main(String[] args) in C:\Users\denis\Documents\Visua
l Studio 2008\Websites\MyHomeV2\MyHome.Tasks\Program.cs:line 87

My code is:

HtmlWrapper.InsertAfter(ContentNode, HtmlWrapper.SelectSingleNode("//div[@id='breadcrumb']"));

And, as already mentioned, I printed both HtmlWrapper and HtmlWrapper.SelectSingleNode ("// div [@id = 'breadcrumb']") on the console and can see the node on the screen. Any ideas on where I made a mistake here?

Thanks Denis

+5
source share
1 answer

, , InsertAfter , refChild node, InsertAfter on. ( //) div node, , node, refChild, HtmlWrapper.

HtmlWrapper.SelectSingleNode("//div[@id='breadcrumb']") , InsertAfter ParentNode.

+6

All Articles