Buscar

Este contenido no está disponible en el idioma seleccionado.

Chapter 33. XQuery

download PDF

Overview

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

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

To use XQuery in your routes you need to add a dependency on camel-saxon to your project as shown in Example 33.1, “Adding the camel-saxon dependency”.

Example 33.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>

Camel on EAP deployment

The camel-saxon component is supported by the Camel on EAP (Wildfly Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container.

Static import

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.component.xquery.XQueryBuilder.xquery;

Variables

Table 33.1, “XQuery variables” lists the variables that are accessible when using XQuery.

Table 33.1. XQuery variables
VariableTypeDescription

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

Example 33.2, “Route using XQuery” shows a route that uses XQuery.

Example 33.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>
Red Hat logoGithubRedditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

© 2024 Red Hat, Inc.