How to use XPath function in a XPathExpression instance programatically?
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
)
How to use XPath-Functions like exists() in C#?
The reason is that it can't use functions without a namespace manager, however, you don't need to use functions, and your code is using that function in the wrong way. you don't need the function exists() to see if something exists, from what I see you are using
//LogicUnit[exists(Level[@val = 'R'])]
where you mean
//LogicUnit[Level[@val = 'R']]
odoo, how to create a correct xpath expression
If you look carefully in the view_users_form code, you will see that the page is named references
and not preferences
.
Try the following XPath:
<xpath expr="//page[@name='references']" position="after">
<page string="Properties" name="property_ids">
<field name="property_ids"/>
</page>
</xpath>
XPath expression to find all elemnts that exist
Assuming that $tag
is stored as a XPath string variable, you can try to filter element by comparing its name as follow :
StringBuffer expression = new StringBuffer("//*[name()=$tag]/text()");
problem getting xpath function ends-with() to work while contains() works fine
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
)
When calling format-number XPath function, I receive error: Namespace Manager or XsltContext needed.
Unfortunately, format-number
function is not supported by MS XPath. It doesn't contain a lot of functions of XSLT. You can find all supporting functions in picture from post here.
But you can have to create your own function here. In article from above you can found my 3 function examples (if-else, format and current).
Sorry, my native language is Russian, but there is translation button. So, you need only take a look on the 1st image and check example code from the first download link. I hope you can copy code and implement your needed functionality for format-number
.
PHP XPath ends-with
from How to use XPath function in a XPathExpression instance programatically?
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()
orfalse()
) as:
ends-with($str1, $str2)
so for your example, the following xpath should work:
//tr[/td/a/img['_imgProductImage' = substring(@id, string-length(@id) - 15)]
you will probably want to add a comment that this is a xpath 1.0 reformulation of ends-with()
.
compiling XPath expression issue
"//bb[name/text()='" + c_name +"']/value"
Note the single quotes surrounding the reference to c_name
.
You could argue that the alternative using String.format()
"//bb[name/text()='%s']/value".format(c_name)
is more readable.
As dogbane notes, this won't work if the variable value contains quotes itself. For a more complex but safer solution see this SO answer.
Related Topics
Wpf Textblock Memory Leak When Using Font
How to Cast a Generic Enum to Int
Topmost Form, Clicking "Through" Possible
How to Draw a Rounded Rectangle in C#
Wpf Controls Needed to Build Chess Application
Is There an Entity Framework 7 Database-First Poco Generator
Get the Decimal Part from a Double
Formatting a C# String with Identical Spacing in Between Values
C#: How to Add Subitems in Listview
Linq to Xml - Update/Alter the Nodes of an Xml Document
Cannot Deserialize JSON Array into Type - JSON.Net
Print HTML Document from Windows Service Without Print Dialog
Registry.Localmachine.Opensubkey() Returns Null
Regex to Match All Us Phone Number Formats
Escape Quote in C# for JavaScript Consumption
Global Setting for Asnotracking()
Linq to Objects - Return Pairs of Numbers from List of Numbers