Contact Us 1-800-596-4880

@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.

public class MyComponent {
    public Object process(@XPath("/Envelope") Document doc) {
        // do stuff
    }
}

You can also use multiple expressions -

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 -

<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 -

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