HTML Agility Pack select all header?

html html-agility-pack

Question

I have a complex HTML document, has so many headings, can HTMLAgilityPack select all of headings in one time query? The result should keep the heading's orginal sequence.

Can anyone know this? thanks

Accepted Answer

Yes you can do something like this using XPath

var xpath = "//*[self::h1 or self::h2 or self::h3 or self::h4]";
foreach (var node in doc.DocumentNode.SelectNodes(xpath))
{
  //do something
}

This respect the order of the tags too. If you want more tags you can add it to the Xpath expression.




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