Determine if a node exists in HTMLAgiltyPack

html-agility-pack windows-8.1 windows-phone-8.1

Question

I want run a foreach loop in a HtmlNode which has been parsed from internet via HtmlWebclass and loadFromWebAsync method. Before running the loop I want to make sure the that the node exists in the HtmlDocument. How do I check that without the help Xpath query because many of the Windows RT and Windows 8.1 version doesn't work with this.

1
0
9/20/2014 6:48:54 AM

Popular Answer

You can use LINQ .Any() method to check if sequence contains any element, for example :

var doc = new HtmlDocument();
.....
var isDivExist = doc.DocumentNode
                    .Descendants("div")
                    .Any();

Or to check if any node in the sequence satisfies specific condition :

var isDivWithSpecificClassExist = doc.DocumentNode
                                     .Descendants("div")
                                     .Any(d => .GetAttributeValue("class", "") == "foo");
0
7/21/2015 8:58:31 AM


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