Chapter 21. JXPath

download PDF


The JXPath language enables you to invoke Java beans using the Apache Commons JXPath language. The JXPath language has a similar syntax to XPath, but instead of selecting element or attribute nodes from an XML document, it invokes methods on an object graph of Java beans. If one of the bean attributes returns an XML document (a DOM/JDOM instance), however, the remaining portion of the path is interpreted as an XPath expression and is used to extract an XML node from the document. In other words, the JXPath language provides a hybrid of object graph navigation and XML node selection.

Adding JXPath package

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

Example 21.1. Adding the camel-jxpath dependency

<!-- Maven POM File -->



Table 21.1, “JXPath variables” lists the variables that are accessible when using JXPath.
Table 21.1. JXPath variables
thisorg.apache.camel.ExchangeThe current Exchange
inorg.apache.camel.MessageThe IN message
outorg.apache.camel.MessageThe OUT message


Example 21.2, “Routes using JXPath” shows a route that use JXPath.

Example 21.2. Routes using JXPath

    <from uri="activemq:MyQueue"/>
      <jxpath>in/body/name = 'James'</xpath>
      <to uri="mqseries:SomeOtherQueue"/>
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.