SelectSingleNode as lowercase

I have looked on SO and found a lot of Q&A that could be the same type of problem, but I can't get mine to work, im doing something wrong.

When I extract certain tags <meta

, I do it this way

HtmlNode clnode = 
htmlDoc.DocumentNode.SelectSingleNode("//meta[@http-equiv='content-type']");

      

This work is just fine, except that it doesn't fit

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

      

Ive tried using a lower case () function like this,

HtmlNode ctnode = 
htmlDoc.DocumentNode.SelectSingleNode("//meta[lower-case(@http-equiv)='content-type']");

      

but that won't work.

I am using the latter HtmlAgilityPack

.

How can I solve this? Maybe a better way?

+3


source to share


1 answer


If you want to use xpath selection it HtmlAgilityPack

uses XPath 1.0 as far as I know , so you have to resort to some ugly hacks like:

HtmlNode clnode = htmlDoc.DocumentNode.SelectSingleNode("//meta[translate(@http-equiv,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='content-type']");

      



Alternatively, you can simply use LINQ:

var clnode= htmlDoc.DocumentNode
                   .Elements("meta")
                   .SingleOrDefault(el => el.Attributes["http-equiv"].Value.ToLower() == "content-type");

      

+4


source







All Articles