Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Agility Pack select all header?

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

like image 720
sendreams Avatar asked Dec 26 '22 12:12

sendreams


1 Answers

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.

like image 171
Victor Sigler Avatar answered Dec 31 '22 16:12

Victor Sigler