Luk*_*hen 5 xpath operator-precedence
我正在写一个xpath表达式来实现这个目的:
//parent[(childA[contains(.,"foo")] or childB[contains(.,"foo")]) AND (childA[contains(.,"bar")] or childB[contains(.,"bar")])]
Run Code Online (Sandbox Code Playgroud)
这是选择其子项(childA或childB或childA和childB一起)包含字符串"foo"和"bar"的父项.
我不确定是否正确使用AND之前和之后的括号.xpath可以这样括号吗?
提前致谢!!
见http://www.w3.org/TR/xpath/#section-Expressions.特别是:
Parentheses may be used for grouping.
Run Code Online (Sandbox Code Playgroud)
和
NOTE: The effect of the above grammar is that the order of precedence is
(lowest precedence first):
or
and
=, !=
<=, <, >=, >
and the operators are all left associative. For example, 3 > 2 > 1 is
equivalent to (3 > 2) > 1, which evaluates to false.
Run Code Online (Sandbox Code Playgroud)