portion of test.xml
<tr class="a"> <td align="left" nowrap="true">desc1</td> <td align="left">desc2</td> <td>desc3</td> <td align="left">desc4</td> <td align="left">desc5</td> <td>desc6</td> <td>desc7</td> <td>desc8</td> <td class="nr">desc9</td> </tr>
//create XpathNavigator to get the last value inside td i.e. desc9
> HtmlDocument document = new HtmlDocument(); document.Load(Server.MapPath("test.xml")); XPathNavigator xPathNavigator = document.CreateNavigator(); object o = xPathNavigator.Evaluate("/table/tbody/tr/td");
The debugger shows the value can be evaluated as below which is very cumbersome.
What is the best way to get to desc9?
I haven't used the XPathNavigator but here is a similar solution with the SelectNodes/SelectSingleNode style and the HTML Agility Pack.
string xPathSearch = "/table/tbody/tr"; HtmlNode tableRow = doc.DocumentNode.SelectSingleNode(xPathSearch); string description9 = tableRow.ChildNodes.InnerText;
string xPathSearch = "/table/tbody/tr/td"; HtmlNode tableColumn = doc.DocumentNode.SelectSingleNode(xPathSearch); string description9 = tableColumn.InnerText;
FYI - The best documentation on the HTML Agility pack seems to be the samples included with the Source. Not sure why that isn't a separate download in the documentation.
I think you are going about this wrong.
I believe all you should need to do is something along the lines of:
I can't find an online copy of the docs to link you to but you can check the docs found at http://htmlagilitypack.codeplex.com/releases/view/44954 for more details.
Also if you are just reading XML is there any reason why you are using the html agility pack or is it just your test file that is valid XML?