Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:42:03+00:00 2026-05-29T04:42:03+00:00

When I use SelectSingleNode(//meta[@name=’keywords’]) it doesn’t work, but when I use the same case

  • 0

When I use

SelectSingleNode("//meta[@name='keywords']")

it doesn’t work, but when I use the same case that used in original document it works good:

SelectSingleNode("//meta[@name='Keywords']")

So the question is how can I set case ignoring?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:42:05+00:00Added an answer on May 29, 2026 at 4:42 am

    If you need a more comprehensive solution, you can write an extension function for the XPath processor which will perform a case insensitive comparison. It is quite a bit of code, but you only write it once.

    After implementing the extension you can write your query as follows

    "//meta[@name[Extensions:CaseInsensitiveComparison('Keywords')]]"
    

    Where Extensions:CaseInsensitiveComparison is the extension function implemented in the sample below.

    NOTE: this is not well tested I just threw it together for this response so the error handling etc. is non-existent!

    The following is the code for the custom XSLT Context which provides one or more extension functions

    using System;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    using System.Xml;
    using HtmlAgilityPack;
    
    public class XsltCustomContext : XsltContext
    {
      public const string NamespaceUri = "http://XsltCustomContext";
    
      public XsltCustomContext()
      {
      }
    
      public XsltCustomContext(NameTable nt) 
        : base(nt)
      {    
      }
    
      public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)
      {
        // Check that the function prefix is for the correct namespace
        if (this.LookupNamespace(prefix) == NamespaceUri)
        {
          // Lookup the function and return the appropriate IXsltContextFunction implementation
          switch (name)
          {
            case "CaseInsensitiveComparison":
              return CaseInsensitiveComparison.Instance;
          }
        }
    
        return null;
      }
    
      public override IXsltContextVariable ResolveVariable(string prefix, string name)
      {
        return null;
      }
    
      public override int CompareDocument(string baseUri, string nextbaseUri)
      {
        return 0;
      }
    
      public override bool PreserveWhitespace(XPathNavigator node)
      {
        return false;
      }
    
      public override bool Whitespace
      {
        get { return true; }
      }
    
      // Class implementing the XSLT Function for Case Insensitive Comparison
      class CaseInsensitiveComparison : IXsltContextFunction
      {
        private static XPathResultType[] _argTypes = new XPathResultType[] { XPathResultType.String };
        private static CaseInsensitiveComparison _instance = new CaseInsensitiveComparison();
    
        public static CaseInsensitiveComparison Instance
        {
          get { return _instance; }
        }      
    
        #region IXsltContextFunction Members
    
        public XPathResultType[] ArgTypes
        {
          get { return _argTypes; }
        }
    
        public int Maxargs
        {
          get { return 1; }
        }
    
        public int Minargs
        {
          get { return 1; }
        }
    
        public XPathResultType ReturnType
        {
          get { return XPathResultType.Boolean; }
        }
    
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator navigator)
        {                
          // Perform the function of comparing the current element to the string argument
          // NOTE: You should add some error checking here.
          string text = args[0] as string;
          return string.Equals(navigator.Value, text, StringComparison.InvariantCultureIgnoreCase);        
        }
        #endregion
      }
    }
    

    You can then use the above extension function in your XPath queries, here is an example for our case

    class Program
    {
      static string html = "<html><meta name=\"keywords\" content=\"HTML, CSS, XML\" /></html>";
    
      static void Main(string[] args)
      {
        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(html);
    
        XPathNavigator nav = doc.CreateNavigator();
    
        // Create the custom context and add the namespace to the context
        XsltCustomContext ctx = new XsltCustomContext(new NameTable());
        ctx.AddNamespace("Extensions", XsltCustomContext.NamespaceUri);
    
        // Build the XPath query using the new function
        XPathExpression xpath = 
          XPathExpression.Compile("//meta[@name[Extensions:CaseInsensitiveComparison('Keywords')]]");
    
        // Set the context for the XPath expression to the custom context containing the 
        // extensions
        xpath.SetContext(ctx);
    
        var element = nav.SelectSingleNode(xpath);
    
        // Now we have the element
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
Use case: user clicks the link on a webpage - boom! load of files
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
We use a data acquisition card to take readings from a device that increases
I plan to use dom4j DOM Document as a static cache in an application
I realize this is a repost but I needed to as I can't use
I have some c# code running on sharepoint that i use to check inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.