HTMLAgilityPack ChildNodes index works, named node does not

Posted by XgenX on Stack Overflow See other posts from Stack Overflow or by XgenX
Published on 2010-03-11T19:31:16Z Indexed on 2010/03/11 19:34 UTC
Read the original article Hit count: 508

I am parsing an XML API response with HTMLAgilityPack. I am able to select the result items from the API call. Then I loop through the items and want to write the ChildNodes to a table. When I select ChildNodes by saying something like:

sItemId = dnItem.ChildNodes(0).innertext

I get the proper itemId result. But when I try:

sItemId = dnItem.ChildNodes("itemId").innertext

I get "Referenced object has a value of 'Nothing'."

I have tried "itemID[1]", "/itemId[1]" and a veriety of strings. I have tried SelectSingleNode and ChildNodes.Item("itemId").innertext. The only one that has worked is using the index.

The problem with using the index is that sometimes child elements are omitted in the results and that throw off the index.

Anybody know what I am doing wrong?

© Stack Overflow or respective owner

Related posts about htmlagilitypack

Related posts about selectsinglenode