AND和OR的xpath逻辑运算符优先级,不带括号

时间:2014-03-19 01:26:47

标签: xpath operator-precedence

我正在写一个xpath表达式来实现这个目的:

//parent[(childA[contains(.,"foo")] or childB[contains(.,"foo")]) AND (childA[contains(.,"bar")] or childB[contains(.,"bar")])]

用于选择其子项(childA或childB或childA和childB一起)包含字符串“foo”和“bar”的父项。

我不确定是否正确使用了AND之前和之后的括号。 xpath可以有这样的括号吗?

提前致谢!!

1 个答案:

答案 0 :(得分:7)

http://www.w3.org/TR/xpath/#section-Expressions。特别是:

Parentheses may be used for grouping.

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.