Case insensitive?

Topics: User Forum
Nov 3, 2006 at 7:21 PM
I'm going to test this, but to validate my tests (or if someone else knows before I finish), does the HtmlAgilityPack work case insensitively? I.E., if I search for a node using one case, but the HTML is another, will it still find it?

For example, will:
htmlDoc.DocumentNode.SelectSingleNode( "//BODY" );

return the body node if in the HTML it is '<body>'?
Nov 3, 2006 at 7:26 PM
My preliminary testing suggests that it IS case insensitive. Very nice.
Nov 9, 2006 at 11:22 AM

Absolutely. This is due to the fact that XML / XPATH is case sensitive.
Jan 18, 2007 at 7:26 PM
public static string XpathElementCaseInsensitive(string elementName)
return string.Format("//node()translate(name(), '{0}', '{1}') = '{1}'", elementName.ToLower(), elementName.ToUpper());

Jul 24, 2012 at 7:11 AM
Edited Jul 24, 2012 at 8:05 AM

tests are case sensitive

some node names aren't

you have to either do 3 queries for "url", "Url", "URL" or use the translation function to get the redirect url

//meta[contains(@content, 'url')]

I can confirm that META, CONTENT, A and HREF are case insensitive.

translate should work in XPath 1 whereas lower-case() is an XPath 2.0 function - It would be really nice to be able to use this.


I wrote a little function for getting the redirect url.  It could be a lot simpler if i could figure out how to use translate with it.



        static string getRedirectUrl(string html)
            HtmlDocument doc = new HtmlDocument();
            //meta content contains url=, but 'url' is case sensitive in this case
            //will only test for aaa,Aaa,AAA but nothing crazier than that

            string[] _URL = { "url", "Url", "URL" };
            for (int mode_URL = 0; mode_URL < _URL.Length; mode_URL++)
                var p = doc.DocumentNode.SelectNodes(string.Format("//meta[contains(@content, '{0}')]", _URL[mode_URL]));
                if (p != null)
                    if (p.Count() == 1)
                        string redirectURL = "";
                        var node = p.Where(k => k.Attributes["content"] != null).Single();
                        if (node != null)
                                string rawValue = node.Attributes["content"].Value;
                                int pos1 = rawValue.IndexOf('=');
                                if (pos1 > -1)
                                    redirectURL = rawValue.Substring(pos1 + 1).Trim();
                            catch { }
                        if (!string.IsNullOrEmpty(redirectURL))
                            return redirectURL;
            return "";
Jan 28, 2013 at 2:20 PM
Edited Jan 29, 2013 at 5:06 AM

Hi ,

Can you please suggest what is the solution for this.

How to search for a node without case sensitivity?


Can any one explain me what are 

"OptionOutputUpperCase" and  "OptionOutputOriginalCase"  are?

Any help will be appreciated.