HTML agility pack for Direct Descendants

.net html-agility-pack

Question

I have a specific html node and i want to get the 2nd aka last direct descendant. So after writing .Descendants("div") i wrote ls.Last(). I actually got the last div in the 2nd descendant. Not what i am expecting. How do i get only the direct descendants? or how do i get the descendant with a specific classname? because "div.postBody" would be a suitable alternative.

1
0
5/18/2010 5:03:05 PM

Accepted Answer

Using XPath would give you what you want. So for direct descendants only you can use -

htmlNode.SelectNodes("/div");

Or if you need to search by specific classname then -

htmlNode.SelectNodes("//div[@class='postBody']");
1
6/9/2010 8:40:33 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow