How to use XPath function in a XPathExpression instance programatically?

前端 未结 1 1385
走了就别回头了
走了就别回头了 2020-11-29 11:30

My current program need to use programatically create a XPathExpression instance to apply to XmlDocument. The xpath needs to use some XPath functions like \"ends-with\". How

相关标签:
1条回答
  • 2020-11-29 11:53

    The function ends-with() is not defined for XPath 1.0 but only for XPath 2.0 and XQuery.

    You are using .NET. .NET at this date does not implement XPath 2.0, XSLT 2.0 or XQuery.

    One can easily construct an XPath 1.0 expression, the evaluation of which produces the same result as the function ends-with():

    $str2 = substring($str1, string-length($str1)- string-length($str2) +1)

    produces the same boolean result (true() or false()) as:

    ends-with($str1, $str2)

    In your concrete case you just need to substitute the right expressions for $str1 and $str2. They are, accordingly, /myXml/data and 'World'.

    So, the XPath 1.0 expression to use, that is equivalent to the XPath 2.0 expression ends-with(/myXml/data, 'World') is:

    'World' = 
       substring(/myXml/data,
                 string-length(/myXml/data) - string-length('World') +1
                 )
    
    0 讨论(0)
提交回复
热议问题