Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-907

...

Code Block
Namespaces ns = new Namespaces("c", "http://acme.com/cheese");

from("direct:start").filter().
    xpath("/c:person[@name='James']", ns).
    to("mock:result");

Variables

Variables in XPath is defined in different namespaces. The default namespace is http://activemq.apache.org/camel/schema/springImage Added.

Namespace URI

Local part

Type

Description

http://camel.apache.org/xml/in/Image Added

in

Message

the exchange.in message

http://camel.apache.org/xml/out/Image Added

out

Message

the exchange.out message

http://camel.apache.org/xml/variables/environment-variablesImage Added

env

Object

OS environment variables

http://camel.apache.org/xml/variables/system-propertiesImage Added

system

Object

Java System properties

http://camel.apache.org/xml/variables/exchange-propertyImage Added

 

Object

the exchange property

Camel will resolve variables according to either:

  • namespace given
  • no namespace given

Namespace given

If the namespace is given then Camel is instructed exactly what to return. However when resolving either in or out Camel will try to resolve a header with the given local part first, and return it. If the local part has the value body then the body is returned instead.

No namespace given

If there is no namespace given then Camel resolves only based on the local part. Camel will try to resolve a variable in the following steps:

  • from variables that has been set using the variable(name, value) fluent builder
  • from message.in.header if there is a header with the given key
  • from exchange.properties if there is a property with the given key

Functions

Camel adds the following XPath functions that can be used to access the exchange:

Function

Argument

Type

Description

$body

none

Object

The message body. Will return the in message body if using no/default or the in namespace. Will return the out body if using the out namespace.

$header

the key

Object

The message header. Will return the in message header if using no/default or the in namespace. Will return the out message if using the out namespace.

$out-body

none

Object

The message.out.body

$out-header

the key

Object

The message.out.header

Using XML configuration

If you prefer to configure your routes in your Spring XML file then you can use XPath expressions as follows

...