I have a table like this:
<table border="0" cellpadding="0" cellspacing="0" id="table2">
<tr>
<th>Name
</th>
<th>Age
</th>
</tr>
<tr>
<td>Mario
</td>
<th>Age: 78
</td>
</tr>
<tr>
<td>Jane
</td>
<td>Age: 67
</td>
</tr>
<tr>
<td>James
</td>
<th>Age: 92
</td>
</tr>
</table>
and I am using html agility pack to parse it. I have tried this code but it is not returning expected results: Here is the code:
foreach (HtmlNode tr in doc.DocumentNode.SelectNodes("//table[@id='table2']//tr"))
{
//looping on each row, get col1 and col2 of each row
HtmlNodeCollection tds = tr.SelectNodes("td");
for (int i = 0; i < tds.Count; i++)
{
Response.Write(tds[i].InnerText);
}
}
I am getting each column because I would like to do some processing on the contents returned.
What am I doing wrong?