Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

@XPath Annotation

A parameter injection annotation that can be used on component entry points and transformer methods, this annotation can be used to execute an Xpath expression on the message payload with the result being passed into the method. For example, if you are expecting an XML document, this can be injected and an XPath expression evaluated against it. Note that any type conversion will be done for you automatically.


         
      
1
2
3
4
5
public class MyComponent {
    public Object process(@XPath("/Envelope") Document doc) {
        // do stuff
    }
}

You can also use multiple expressions -


         
      
1
2
3
4
5
6
public class MyComponent {
    public Object process(@XPath("/Envelope") Document doc
                                        @XPath("/Envelope/@id") String id) {
        // do stuff
    }
}

Namespaces

Namespaces can be configured in the Mule Configuration using the XML Namespaces, these will be made available for this annotation.

First declare the namespace using the Namespace Manager -


         
      
1
2
3
<mulexml:namespace-manager includeConfigNamespaces="true">
    <mulexml:namespace prefix="e" uri="http://foo.com/message/envelope"/>
</mulexml:namespace-manager>

Then you can reference the 'e' namespace in the XPath expression -


         
      
1
2
3
4
5
public class MyComponent {
    public Object process(@XPath("/e:Envelope") Document doc) {
        // do stuff
    }
}

In this topic:

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+