Xpath query for ends with

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newasp
    New Member
    • Oct 2007
    • 7

    Xpath query for ends with

    Hi

    I was wondering if we can use Xpath query for finding nodes that ends with a 'string' value entered by the user. For example we can use the following query for finding the nodes that starts with a string

    Code:
     XmlNodeList nodeList = xmlDoc.SelectNodes("//Country[starts-with(@Name,'a')]");
    When I tried replacing 'starts -with' with 'ends- with' in the above query, it showed the error below

    Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    How to write an Xpath query for finding nodes that ends with a particular string? Or is their any other method? I am using ASP.net -C#

    Thanks a lot
    Kim
  • newasp
    New Member
    • Oct 2007
    • 7

    #2
    Hi

    I found the solution; need to use substring function

    XmlNodeList nodeList = xmlDoc.SelectNo des("//Country[substring(@Name , string-length(@Name) - string-length('" + this.TextBox1.T ext + "')+ 1, string-length(@Name))= '" + this.TextBox1.T ext + "']");

    BTW, my the xml file is as follows
    <World>
    <Country name ="Denmark"/>
    <Country Name = "India"/>
    </World>

    Comment

    Working...