Reputation: 71
I am trying to run below XPath expressions in Mule. Its giving me errors one after another. Can someone help me correcting these Mule XPath expressions :
<xm:namespace-manager includeConfigNamespaces="true">
<xm:namespace prefix="acord" uri="ACORD.org/Standards/Life/2" />
<xm:namespace prefix="soap" uri="schemas.xmlsoap.org/soap/envelope/" />
</xm:namespace-manager>
<set-variable variableName="pwaHolding"
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value" />
<set-variable variableName="pwaPolNumber"
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Holding[@id=$pwaHolding]/acord:Policy/acord:PolNumber').text]" />
I am getting below exception when trying to execute above XPATH expressions :
Message :Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unexpected token: 37]
[Near : {... @tc == '37']/@OriginatingObjec ....}]
^
[Line: 1, Column: 96] (org.
mvel2.CompileException)
org.mvel2.compiler.ExpressionCompiler:247 (null)
2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:211 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractTransformer:123 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
[Error: unexpected token: 37]
[Near : {... @tc == '37']/@OriginatingObjec ....}] ^
[Line: 1, Column: 96]
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:247)
at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:1944)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:862)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Hi David,
I even after replacing '
with "
I am still getting below error :
Message : Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String Code : MULE_ERROR--2 -------------------------------------------------------------------------------- Exception stack is: 1. [Error: unexpected token: 37] [Near : {... @tc == '37']/@OriginatingObjec ....}] ^ [Line: 1, Column: 96] (org.mvel2.CompileException) org.mvel2.compiler.ExpressionCompiler:247 (null) 2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException) org.mule.el.mvel.MVELExpressionLanguage:211 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException) org.mule.transformer.AbstractTransformer:123 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
I have my second XPATH expression in question which is also failing. Please help me get around this as well
Upvotes: 0
Views: 3034
Reputation: 33413
The error comes from the fact you use a '
inside a string delimited by '
, which can not work. For example in the following expression the issue is around '37'
:
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value" />
Another issue is that a closing ]
is missing at the end of the MEL expression.
Try with:
value="#[xpath("//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID").value" />
Looking at your second XPath, I see [@id=$pwaHolding]
. I assume that at this point you are trying to use the pwaHolding
flow variable extracted by the first XPath. This will not work as MVEL does not have string interpolation. You need to instead use concatenation and, by the way, not forget to single quote the value @id
is compared to:
[@id='" + pwaHolding + "']
Upvotes: 3