views:

363

answers:

1

Assuming nested tables don't have unique attributes ( id , class or anything else ) to get the required one via

doc.DocumentNode.SelectSingleNode("//table[@width='500']")

Does XPath prohibit using table several times in its path ?

foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/center/table"))

throws exception as SelectNodes returns null.

If so how to tackle parsing of html with nested tables without specific attributes with Agility Pack ?

+1  A: 

I just missed "td" tag in my path. So

foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/td/center/table/tr/td/center/table"))

does work. That actually answers my question. Other workaround to get the same table assuming there are unique attribute values in parent elements could be

HtmlNode tbl = doc.DocumentNode.SelectSingleNode("//td[@height='643']/center/table");
MicMit