A MEL function capable of evaluation XPath expressions by delegating into an instance
of
XPathEvaluator
The function will now accept the following arguments (in order):
| expression (required String) |
The Xpath expression to be evaluated. Cannot be null or blank. |
| input (optional Object, defaults to the message payload) |
The input data on which the expression is going to be evaluated. This is an optional argument, it defaults to the message payload if not provided. |
| Output type (optional String, defaults to ?STRING?) |
When executing an XPath expression, a developer might have very different intents. Sometimes you want to retrieve actual data,
sometimes you just want to verify if a node exists. Also, the JAXP API (JSR-206) defines the standard way for a Java application to handle XML, and therefore,
how to execute XPath expressions. This API accounts for the different intents a developer might have and allows choosing from a list of possible output types.
We consider this to be a really useful features in JAXP, and we also consider that many Java developers that are familiar with this API would appreciate
that Mule accounts for this while hiding the rest of the API's complexity. That is why there's a third parameter (optional, String),
which will allow specifying one of the following:
- BOOLEAN: returns the effective boolean value of the expression, as a java.lang.Boolean. This is the same as wrapping the expression in a call of the XPath boolean() function.
- STRING: returns the result of the expression converted to a string, as a java.lang.String. This is the same as wrapping the expression in a call of the XPath string() function.
- NUMBER: returns the result of the expression converted to a double as a java.lang.Double. This is the same as wrapping the expression in a call of the XPath number() function.
- NODE: returns the result the result as a node object.
- NODESET: returns a
NodeList.
|
Input types
This function supports the following input types:
If the input if not of any of these types, then we'll attempt to use a registered transformer to transform the input into a DOM document or Node.
If no such transformer can be found, then an
IllegalArgumentException will be thrown.
This function will verify if the input is a consumable type (streams, readers, etc). Because evaluating the expression over a consumable input
will cause that source to be exhausted, in the cases in which the input value was the actual message payload
(no matter if it was given explicitly or by default), it will update the output message payload with the result obtained from consuming the input.