32.7. predicates

基本 predicates

例如,您可以在 Java DSL 或 XML DSL 中使用 xpath,其中 predicate 预期为将 predicate 用作 filter () 处理器的参数,或作为 when () 子句的参数。

例如,以下路由会过滤传入的信息,仅当 /person/city 元素包含值 London 时传递信息:

from("direct:tie")
    .filter().xpath("/person/city = 'London'").to("file:target/messages/uk");

以下路由评估 when () 子句中的 XPath predicate:

from("direct:tie")
    .choice()
        .when(xpath("/person/city = 'London'")).to("file:target/messages/uk")
        .otherwise().to("file:target/messages/others");

XPath predicate operator

XPath 语言支持标准 XPath predicate operator,如 表 32.2 “XPath 语言的 Operator” 所示。

表 32.2. XPath 语言的 Operator

Operator描述

=

等于.

!=

不等于.

>

大于.

>=

大于等于.

<

小于.

小于或等于.

将两个 predicates 与逻辑 相结合。

或者

将两个 predicates 与逻辑 包或 相结合。

not()

negate predicate 参数。