HtmlAgilityPack - Selecting Multiple Nodes

html-agility-pack linq windows-phone-8.1

Question

The lack of a formal publication ofHtmlAgilityPack for windows phone 8.1 or WinRT , Manually referencing the dll prevents calling theSelectNodes() function that allows me to pass aXPATH as a variable.

I'm seeking for a comparable Linq query that will allow me to choose different nodes based on their class names. Simply said, I want to keep all of the nodes in aHtmlNodeCollection where the node beginsdiv both theclass to thatdiv is XXX.

1
1
8/23/2014 10:23:55 PM

Accepted Answer

Your phrase was converted into a LINQ expression by HtmlAgilityPack as follows:

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

or just state that you are solely interested in<div> nodes:

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

Over resultsIEnumerable<HtmlNode> in place ofHtmlNodeCollection , but I don't think that matters much.

3
8/23/2014 10:22:45 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