0

我有一个这样的xml:

<order>
  <orderheader>
    <orderissuedate>1/11/2013</orderissuedate>
  </orderheader>
</order>

在使用 INFO 设置的 mule 记录器组件中,我有一个 mule 表达式,它试图打印出 orderissuedate 1/11/2013。

我使用表达式:

[xpath('/order/orderheader//orderissuedate')] 不起作用。

我也试过:#[xpath('/order/orderheader/orderissuedate/text()').text] 那也没有用。

有人可以告诉我正确的 xpath 表达式是什么。我收到此错误消息:

java.lang.RuntimeException:org.mule.api.MuleRuntimeException:无法评估 XPath 表达式:“/Order/OrderHeader/OrderIssueDate/text()”

我已经使用在线 xpath 检查器测试了这些 xpath 表达式,它们似乎可以工作。谢谢你的帮助。

这是原始的xml:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Order>
<Order
      xmlns:core="rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <OrderHeader>
    <OrderNumber>
      <BuyerOrderNumber>111111</BuyerOrderNumber>
    </OrderNumber>
    <OrderIssueDate>2013-06-28T08:40:12</OrderIssueDate>
    <OrderReferences>
      <AccountCode>
        <core:RefNum></core:RefNum>
      </AccountCode>
    </OrderReferences>
  </OrderHeader>
</Order>

以及 mule 的错误输出:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
java.lang.RuntimeException: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "/OrderIssueDate"
    at org.mule.module.xml.el.XPathFunction.call(XPathFunction.java:50)
    at org.mule.el.mvel.MVELFunctionAdaptor.call(MVELFunctionAdaptor.java:38)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1011)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
    at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
    at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
    at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
    at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
    at org.mvel2.MVEL.executeExpression(MVEL.java:942)
    at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:50)
    at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:214)
    at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:163)
    at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:142)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:220)
    at org.mule.expression.DefaultExpressionManager$2.match(DefaultExpressionManager.java:481)
    at org.mule.util.TemplateParser.parse(TemplateParser.java:153)
    at org.mule.util.TemplateParser.parse(TemplateParser.java:130)
    at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:477)
    at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:436)
    at org.mule.api.processor.LoggerMessageProcessor.log(LoggerMessageProcessor.java:89)
    at org.mule.api.processor.LoggerMessageProcessor.process(LoggerMessageProcessor.java:71)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:95)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
    at com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor.process(DataMapperMessageProcessor.java:132)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:122)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:192)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:185)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:20)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:34)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:18)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:58)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:48)
    at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:54)
    at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:44)
    at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
    at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:32)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:17)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:113)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:34)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:184)
    at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:43)
    at org.mule.work.WorkerContext.run(WorkerContext.java:311)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "/OrderIssueDate"
    at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.evaluate(AbstractXPathExpressionEvaluator.java:144)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:311)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:230)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:186)
    at org.mule.module.xml.el.XPathFunction.call(XPathFunction.java:43)
    ... 60 more
Caused by: org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
    at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:252)
    at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:355)
    at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:313)
    at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.getPayloadForXPath(AbstractXPathExpressionEvaluator.java:154)
    at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.evaluate(AbstractXPathExpressionEvaluator.java:115)
    ... 64 more
ERROR 2013-08-26 00:40:49,893 [[mule_egc2].EGC_FlowFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
Code                  : MULE_ERROR-236
--------------------------------------------------------------------------------
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
  org.mule.registry.MuleRegistryHelper:252 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
    at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:252)
    at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:355)
    at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:313)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
4

6 回答 6

3

用这个:

<logger message="OrderIssueDate is #[xpath('//Order/OrderHeader/OrderIssueDate').text]" level="INFO" /> 

确保为您的 XML 元素层次结构正确使用大小写。您order在顶级 XML 中,而Order在较低的 XML 中,依此类推

于 2013-08-26T13:48:26.177 回答
2

根据我的工作的xpath表达式是#[xpath://orderissuedate]要使用记录器打印,你应该使用类似的东西<logger message="#[xpath://orderissuedate]" level="INFO"/>

于 2013-08-26T04:06:50.407 回答
0

从关于答案之一的对话中,以下解决方案应该有效。

<logger message="Value of Order Issue Date  #[xpath('//OrderIssueDate').text]"  level="INFO" />

如果还提供订单的DTD会更好。

于 2013-08-26T14:05:54.467 回答
0

试试这个,它可能会有所帮助:

#[xpath3('//order/orderheader/orderissuedate/text()')]
于 2017-01-17T09:44:34.050 回答
0

如果您正在获取命名空间,您可以像这样使用 mule latest xpath3

[xpath3('//*:orderissuedate/text()')]

于 2017-01-19T08:35:59.583 回答
0

您的原始 XML 似乎有命名空间:-

xmlns:core="rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

因此,如果您需要使用 Xpath 从原始 XML 中提取值,则需要 Mule 命名空间管理器:- https://developer.mulesoft.com/docs/display/current/XML+Namespaces

除此之外,如果您想从上面显示的 XML 中提取值,您可以使用 Mule 3.6 版中的 Mules 最新 Xpath3,它易于使用:- https://developer.mulesoft.com/docs/显示/当前/XPath
希望它可以帮助你:)

于 2015-08-06T06:56:41.723 回答