Show Table of Contents
32.7. Predicates
Basic predicates
You can use
xpath in the Java DSL or the XML DSL in a context where a predicate is expected—for example, as the argument to a filter() processor or as the argument to a when() clause.
For example, the following route filters incoming messages, allowing a message to pass, only if the
/person/city element contains the value, London:
from("direct:tie")
.filter().xpath("/person/city = 'London'").to("file:target/messages/uk");
The following route evaluates the XPath predicate in a
when() clause:
from("direct:tie")
.choice()
.when(xpath("/person/city = 'London'")).to("file:target/messages/uk")
.otherwise().to("file:target/messages/others");XPath predicate operators
The XPath language supports the standard XPath predicate operators, as shown in Table 32.2, “Operators for the XPath Language”.
Table 32.2. Operators for the XPath Language
| Operator | Description |
|---|---|
= | Equals. |
!= | Not equal to. |
> | Greater than. |
>= | Greater than or equals. |
< | Less than. |
<= | Less than or equals. |
or | Combine two predicates with logical and. |
and | Combine two predicates with logical inclusive or. |
not() | Negate predicate argument. |

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.