0
votes

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 &quot; 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

1
Have you configured a namespace manager? What error? Mule version? - David Dossot
Hi David, I am using Mule 3.3.1 and have configured namespace manager as following : <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> - user2324686
I have edited your question to add this bit of info, please do the same and add the error you're receiving in the question. - David Dossot
Hi David, When I am trying to execute above mule expressions, I am getting below exception : org.mule.api.expression.InvalidExpressionException: [Error: unterminated literal] [Near : {... xpath('//acord:TXLife/aco ....}] ^ [Line: 1, Column: 5]: [Error: unterminated literal] [Near : {... xpath('//acord:TXLife/aco ....}] ^ [Line: 1, Column: 5] (org.mule.api.expression.InvalidExpressionException). Message payload is of type: String: - user2324686
Can you please edit your question and add the properly formatted exception in it? It's unreadable in comments, plus the goal is to increase the quality of the question so more people can help. - David Dossot

1 Answers

3
votes

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(&quot;//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID&quot;).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‌='&quot; + pwaHolding + &quot;']