XQuery was originally devised as a query language for data stored in XML form in a database. The XQuery language enables you to select parts of the current message, when the message is in XML format. XQuery is a superset of the XPath language; hence, any valid XPath expression is also a valid XQuery expression.
To use XQuery in your routes you need to add a dependency on
camel-saxon
to your project as shown in
Example 20.1.
Example 20.1. Adding the camel-saxon dependency
<!-- Maven POM File --> ... <dependencies> ... <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> <version>${camel-version}</version> </dependency> ... </dependencies>
Table 20.1 lists the variables that are accessible when using XQuery.
Table 20.1. XQuery variables
Variable | Type | Description |
---|---|---|
exchange | Exchange | The current Exchange |
in.body | Object | The body of the IN message |
out.body | Object | The body of the OUT message |
in.headers. | Object | The IN message header whose key is key |
out.headers. | Object | The OUT message header whose key is key |
key | Object | The Exchange property whose key is key |
Example 20.2 shows a route that uses XQuery.
Example 20.2. Route using XQuery
<camelContext> <route> <from uri="activemq:MyQueue"/> <filter> <language langauge="xquery">/foo:person[@name='James']</language> <to uri="mqseries:SomeOtherQueue"/> </filter> </route> </camelContext>