HtmlAgilityPack - Selecting Multiple Nodes

html-agility-pack linq windows-phone-8.1

Question

As there's no official release of HtmlAgilityPack for windows phone 8.1 or WinRT, Referencing manually the dll doesn't allow to call the SelectNodes() function where I can pass a XPATH as parameter.

I'm looking for an similar Linq query by which I can select multiple nodes depending of the node's class name. In Plain English I want store the all the nodes in a HtmlNodeCollection where the node starts with div and the class of that div is XXX.

Accepted Answer

Translated from your sentence into HtmlAgilityPack's LINQ expression :

var result = doc.DocumentNode
                .Descendants()
                .Where(o => o.Name.StartsWith("div") 
                                && 
                            o.GetAttributeValue("class", "") == "XXX");

or simply mention that you are interested only in <div> nodes :

var result = doc.DocumentNode
                .Descendants("div")
                .Where(o => o.GetAttributeValue("class", "") == "XXX");

Above returns IEnumerable<HtmlNode> instead of HtmlNodeCollection, but that isn't significant IMHO.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why