i have this hap code of which tries to selects sub-node from the main collection of nodes
Dim items As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//channel/item")
For Each item In items
link = item.SelectSingleNode("//link")
title = item.SelectSingleNode("//title")
next
the xml is
<rss version="2.0">
<channel>
<title>title title</title>
<link>http://www.link.com</link>
<description>long decription</description>
<item>
<title>title title</title>
<link>http://www.link.com/</link>
<description> description</description>
</item>
<item>
<title>title title</title>
<link>http://www.link.com/</link>
<description> description</description>
</item>
<item>
<title>title title</title>
<link>http://www.link.com/</link>
<description> description</description>
</item>
</channel>
</rss>
but i don get the appropriate node title and link under item for each of the items.
where am i getting it wrong?
i could have just done
Dim links As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//channel/item/link")
Dim titles As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//channel/item/title")
but i need the link and title for each item
Seems to me like a bug in HtmlAgilityPack. I had issues only retrieving the
InnerTextfor thelinkelement, not the others. For that one, the text was found as its sibling, not as child at least.Anyway, this wouldn’t be the first bug encountered in HtmlAgilityPack, so we should live with it :).
Alternative:
Use an
XmlDocumentsince there’s no HTML involved here. That is an XML.Output: