public class MyComponent {
public Object process(@XPath("/Envelope") Document doc) {
// do stuff
}
}
@XPath Annotation
Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version. |
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.
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
}
}