Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 20. XQuery
Overview Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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.
Java syntax Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
You can pass an XQuery expression to
xquery()
in several ways. For simple expressions, you can pass the XQuery expressions as a string (java.lang.String
). For longer XQuery expressions, you might prefer to store the expression in a file, which you can then reference by passing a java.io.File
argument or a java.net.URL
argument to the overloaded xquery()
method. The XQuery expression implicitly acts on the message content and returns a node set as the result. Depending on the context, the return value is interpreted either as a predicate (where an empty node set is interpreted as false) or as an expression.
Adding the Saxon module Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
To use XQuery in your routes you need to add a dependency on
camel-saxon
to your project as shown in Example 20.1, “Adding the camel-saxon dependency”.
Example 20.1. Adding the camel-saxon dependency
Static import Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
To use the
xquery()
static method in your application code, include the following import statement in your Java source files:
import static org.apache.camel.builder.saxon.XQueryBuilder.xquery;
import static org.apache.camel.builder.saxon.XQueryBuilder.xquery;
Variables Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Table 20.1, “XQuery variables” lists the variables that are accessible when using XQuery.
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.key | Object | The IN message header whose key is key |
out.headers.key | Object | The OUT message header whose key is key |
key | Object | The Exchange property whose key is key |
Example Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Example 20.2, “Route using XQuery” shows a route that uses XQuery.
Example 20.2. Route using XQuery