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

  • SEARCH
  • Home
  • 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 6148213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:14:30+00:00 2026-05-23T19:14:30+00:00

Is there a way in the C# XPath to pass a parameter like you

  • 0

Is there a way in the C# XPath to pass a parameter like you can do with a SQL select? For example:

XPathExpression expr = nav.Compile("/root/employee[@name = @p1]");
expr.SetParameter ("@p1", "Smith");

Where it would then handle all escapes, placing quotes around it, etc.?

  • 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-23T19:14:31+00:00Added an answer on May 23, 2026 at 7:14 pm

    The .net XPath support is for XPath 1.0. However, there is an easy way to add support for variables where you can do the equivilent of a SetParameter() call on a SQL select call. This also gives you support for defining your own functions, like matches(). (This is from my blog – Windward Wrocks.)

    Note: I was not able to find a way to add support for inequalities on dates. If anyone knows of a way to add this, please let me know.

    You need to create a custom XsltContext. Two good references for this are Case-insensitive XPath in .NET and Adding Custom Functions to XPath.

    The code in XPathCustomContext.cs is well documented and straightforward so I’m not going to write about it here. However a couple of notes when using it:

    1. Change the Prefix and Namespace values so you’re not walking on our
      namespace.
    2. You put a variable in the XPath as $name. You pass it in
      XsltArgumentList and have it passed to you in ResolveVariable as
      name (no $).

    And here’s the biggie – you must call all Evaluate() and Select*() calls using XpathExpressions as shown below. If you use the call where you directly pass in the XPath as a string you will get an exception that says you are using an unknown function. This occurs even if you pass in your custom context.

    private object SelectSingleNodeTyped(XPathNavigator nav, string select, XsltArgumentList parameters)
    {
    myContext.ArgList = parameters;
    XPathExpression exp = nav.Compile(myXPathSelect);
    exp.SetContext(myContext);
    object obj = nav.Evaluate(exp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an xpath way to select a given attribute value? For example I
Is there a way of writing an XPath expression to select the content of
Is there a way I can accomplish the following using Nokogiri's xpath() ? doc.xpath(//pod[@id=or('anid','anotherid')])
Is there any way, how I can to identify two xpath values in one.
is there way thats i can preselect an item when the page loads or
is there way how to get name ov event from Lambda expression like with
In PL/SQL Developer v7.1.x, is there way way to ignore large data types in
Terrible title, I know, but is there a way in XPath to get to
Is there an XPath way of recovering directly one specific attribute of preceding sibling
Is there a way to construct an XPath that evaluates whether an element's value

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.