32.7. predicates

基本 predicates

您可以在 Java DSL 中,或者在 predicate 期望的上下文中使用 xpath,作为 filter() 处理器的参数,或作为 when() 子句的参数。

例如,以下路由过滤传入的消息,允许一条信息传递,仅当 /person/city 元素包含值 伦敦 时:

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 运算符,如 表 32.2 “XPath 语言的 Operator” 所示。

表 32.2. XPath 语言的 Operator

Operator描述

=

等于。

!=

不等于.

>

大于.

>=

大于或等于。

<

小于.

小于或等于。

将两个 predicates 与逻辑 组合。

或者

将两个 predicates 与逻辑 inclusive 组合。

not()

negate predicate 参数.