{"id":6097,"date":"2012-08-17T10:06:56","date_gmt":"2012-08-17T09:06:56","guid":{"rendered":"http:\/\/jonas.kihlsten.se\/blog\/?p=6097"},"modified":"2012-08-30T14:20:07","modified_gmt":"2012-08-30T13:20:07","slug":"html-agility-pack-get-all-heading-tags","status":"publish","type":"post","link":"http:\/\/jonas.kihlsten.se\/blog\/2012\/08\/html-agility-pack-get-all-heading-tags\/","title":{"rendered":"Html Agility Pack: Get all heading tags"},"content":{"rendered":"<p>A project I&#8217;m currently working on involves parsing a lot of HTML using the <a href=\"http:\/\/http:\/\/htmlagilitypack.codeplex.com\">Html agility pack<\/a>. One problem I came across was finding all heading level tags between 1 and 6 and here&#8217;s my solution using Xpath:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nstring xpathQuery = &quot;\/\/*&#x5B;starts-with(name(),'h') and string-length(name()) = 2 and number(substring(name(), 2)) &lt;= 6]&quot;;\r\nvar tags = htmlDocument.DocumentNode.SelectNodes(xpathQuery);\r\n<\/pre>\n<p>If someone has a better or alternative solution please let me know in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A project I&#8217;m currently working on involves parsing a lot of HTML using the Html agility pack. One problem I came across was finding all heading level tags between 1 and 6 and here&#8217;s my solution using Xpath: string xpathQuery = &quot;\/\/*&#x5B;starts-with(name(),&#8217;h&#8217;) and string-length(name()) = 2 and number(substring(name(), 2)) &lt;= 6]&quot;; var tags = htmlDocument.DocumentNode.SelectNodes(xpathQuery); &hellip; <a href=\"http:\/\/jonas.kihlsten.se\/blog\/2012\/08\/html-agility-pack-get-all-heading-tags\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Html Agility Pack: Get all heading tags<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,21],"tags":[23,24,22,25],"class_list":["post-6097","post","type-post","status-publish","format-standard","hentry","category-aspnet","category-web","tag-c","tag-html","tag-html-agility-pack","tag-xpath"],"_links":{"self":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/comments?post=6097"}],"version-history":[{"count":9,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6097\/revisions"}],"predecessor-version":[{"id":6109,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6097\/revisions\/6109"}],"wp:attachment":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/media?parent=6097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/categories?post=6097"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/tags?post=6097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}