How to get a Table

Feb 2, 2009 at 2:41 AM
Edited Feb 2, 2009 at 2:42 AM

            I am new to Parsing HTML and also to HTML Agility Pack. I would like to know if it is possible to get a table from the HTML document assuming I know the name of the Table.



Feb 15, 2009 at 10:03 PM
Edited Feb 15, 2009 at 10:03 PM
Looks like this project is dead.

To others who consider using HTML Agility Pack – beware that you will not get any help, if this does not work for you.


As far as my original question regarding getting the Tables, consider something like:


HtmlNodeCollection atts = doc.DocumentNode.SelectNodes("//table");


Remember if you have a Table nested within a Table, it will show up twice.

Feb 16, 2009 at 2:48 PM
Edited Feb 16, 2009 at 11:46 PM

"Remember if you have a Table nested within a Table, it will show up twice."

That's the beauty of using SelectNodes(), you can use SelectSingleNode() if you want to get the first occurance of TABLE element and try researching for XPATH tutorial .. 
if you have something like <table id="etc"> ... </table>
you can just simply use this: HtmlNode n = HtmlDocument.DocumentNode.SelectSingleNode("table[@id='etc']")

Please do take note that this project doesn't cover XPATH tutorial as they made this very wonderfull open source solution for DEALING with XPATHs only.
If you have questions, bug reports, suggestions on HtmlAgilityPack; the developers would greatly appreciate that and probably answer.

You can use my Xpath Testbed:

be productive ;)