32.7. predicates

基本的 predicates

您可以在 Java DSL 或 XML DSL 中使用 xpath,其中 predicate 为 expected iwl-PROFILE-PROFILE 例如,作为 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 operators

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

表 32.2. XPath 语言的 Operator

Operator描述

=

等于.

!=

不等于.

>

大于.

>=

大于 or equals。

<

小于.

小于 or equals。

将两个 predicates 与逻辑 组合。

将两个 predicates 与逻辑 包含 或 组合起来

not()

negate predicate 参数。