...
Wiki Markup |
---|
{snippet:id=example|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathWithNamespacesFilterTest.java} |
...
Variables in XPath is defined in different namespaces. The default namespace is http://activemqcamel.apache.org/camel/schema/spring
.
Namespace URI | Local part | Type | Description |
---|---|---|---|
http://camel.apache.org/xml/in/![]() | in | Message | the exchange.in message |
http://camel.apache.org/xml/out/![]() | out | Message | the exchange.out message |
http://camel.apache.org/xml/variables/environment-variables![]() | env | Object | OS environment variables |
http://camel.apache.org/xml/variables/system-properties![]() | system | Object | Java System properties |
http://camel.apache.org/xml/variables/exchange-property![]() |
| Object | the exchange property |
...
Wiki Markup |
---|
{snippet:id=ex|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/language/XPathFunctionTest.java} |
...
Code Block | ||
---|---|---|
| ||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:foo="http://example.com/person" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemqcamel.apache.org/camel/schema/spring http://activemqcamel.apache.org/camel/schema/spring/camel-spring.xsd"> <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:MyQueue"/> <filter> <xpath>/foo:person[@name='James']</xpath> <to uri="mqseries:SomeOtherQueue"/> </filter> </route> </camelContext> </beans> |
Notice how we can reuse the namespace prefixes, foo in this case, in the XPath expression for easier namespace based XPath expressions!
Examples
Here is a simple example using an XPath expression as a predicate in a Message Filter
Wiki Markup |
---|
{snippet:id=example|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java} |
If you have a standard set of namespaces you wish to work with and wish to share them across many different XPath expressions you can use the NamespaceBuilder as shown in this example
Wiki Markup |
---|
{snippet:id=example|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathWithNamespaceBuilderFilterTest.java} |
...
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathHeaderTest.java} |
...
Wiki Markup |
---|
{snippet:id=example|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringXPathHeaderTest-context.xml} |
...
The default XPath annotation has SOAP and XML namespaces available. If you want to use your own namespace URIs in an XPath expression you can use your own copy of the XPath annotation to create whatever namespace prefixes you want to use.
i.e. cut and paste the XPath annotation code to your own project in a different package and/or annotation name then add whatever namespace prefix/uris you want in scope when you use your annotation on a method parameter. Then when you use your annotation on a method parameter all the namespaces you want will be available for use in your XPath expression.
...