Reputation: 333
I'm using html agility pack and after I got array of nodes:
HtmlNode[] nodes = document.DocumentNode.SelectNodes("//tbody[@class='table']").ToArray();
now i want to run a for loop one each nodes[i]. I've tried this:
for (int i = 0; i < 1; i++)
{
if (t == null)
t = new Model.Track();
HtmlNode[] itemText = nodes[i].SelectNodes("//td[@class='artist']").ToArray();
for (int x = 0; x < itemText.Length; x++)
{ //doing something }
the problem is that the itemtext array isn't focusing on nodes[i] . but brings out an array of all the ("//td[@class='artist']") in the html document. help?
Upvotes: 1
Views: 972
Reputation: 8392
Using //td[@class='artist']
will fetch all columns with artist
class from your document.DocumentNode
.
Using .//td[@class='artist']
(Notice the dot at the begining) will fetch all columns with artist
class from the current selected node, which in your case is nodes[i]
.
Upvotes: 1