复杂的Mule XPath表达式抛出异常

时间:2013-07-24 20:13:26

标签: xpath mule

我试图在Mule中运行XPath表达式。它一个接一个地给我错误。 有人可以帮我纠正这些Mule XPath表达式:

 <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]" />

尝试执行上面的XPATH表达式时,我遇到异常:

    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)

大卫,

我甚至在用'替换&quot;后仍然遇到错误:

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)

我的第二个XPATH表达式问题也失败了。请帮我解决这个问题

    

1 个答案:

答案 0 :(得分:3)

错误来自于您在'分隔的字符串中使用'这一事实,这是行不通的。例如,在以下表达式中,问题出在'37'

附近
value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value" />

另一个问题是在MEL表达式的末尾缺少结束]

尝试:

value="#[xpath(&quot;//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID&quot;).value" />

看看你的第二个XPath,我看到[@id=$pwaHolding]。我假设此时您正在尝试使用第一个XPath提取的pwaHolding流变量。这不起作用,因为MVEL没有字符串插值。你需要使用连接,顺便说一句,不要忘记单引号将值@id与之比较:

[@id‌='&quot; + pwaHolding + &quot;']