如何访问来自 Dataweave 的 XML
How to access the XML which comes out of Dataweave
我尝试访问来自 DataWeave 的 xml 下的元素。它给了我 returns 空值。
DataWeave 脚本是
%dw 1.0
%namespace ns0 urn:abc:dbc:Components
%output text/xml
---
ItemFee:{
product_id:flowVars."Dept_id",
TotalFees: sum payload.ns0#ItemResponse.ns0#Fees.*ns0#Fee.ns0#Fee
}
在这个数据编织之后,我立即有了带有以下消息的记录器节点。
#[message.payload.ItemFee.TotalFees]
我收到错误提示
Execution of the expression "message.payload.ItemFee.TotalFees" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler
我想在这里多说一点。当我在 'Transform Message' 之后立即在记录器中给出以下文本时。控制台中打印的消息没有问题。但是我无法访问 xml 消息中的元素。#[message.payloadAs(java.lang.String)]
MEL 语法仅适用于 Java 对象。由于输出为 XML,您将不得不使用 xpath3
MEL 函数:
https://docs.mulesoft.com/mule-user-guide/v/3.7/xpath#the-xpath3-function
类似于:
#[xpath3('//ItemFee/TotalFees').text]
谢谢瑞安。你的回答对我有帮助。我已经在我的记录器中输入了下面的内容。然后我就可以拿到物品了。
#[xpath3('//ItemFee/TotalFees')]
早些时候我尝试了这些东西,我不确定为什么它不能更早地工作。可能是我忽略了这个问题。 :)
我尝试访问来自 DataWeave 的 xml 下的元素。它给了我 returns 空值。
DataWeave 脚本是
%dw 1.0
%namespace ns0 urn:abc:dbc:Components
%output text/xml
---
ItemFee:{
product_id:flowVars."Dept_id",
TotalFees: sum payload.ns0#ItemResponse.ns0#Fees.*ns0#Fee.ns0#Fee
}
在这个数据编织之后,我立即有了带有以下消息的记录器节点。
#[message.payload.ItemFee.TotalFees]
我收到错误提示
Execution of the expression "message.payload.ItemFee.TotalFees" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler
我想在这里多说一点。当我在 'Transform Message' 之后立即在记录器中给出以下文本时。控制台中打印的消息没有问题。但是我无法访问 xml 消息中的元素。#[message.payloadAs(java.lang.String)]
MEL 语法仅适用于 Java 对象。由于输出为 XML,您将不得不使用 xpath3
MEL 函数:
https://docs.mulesoft.com/mule-user-guide/v/3.7/xpath#the-xpath3-function
类似于:
#[xpath3('//ItemFee/TotalFees').text]
谢谢瑞安。你的回答对我有帮助。我已经在我的记录器中输入了下面的内容。然后我就可以拿到物品了。
#[xpath3('//ItemFee/TotalFees')]
早些时候我尝试了这些东西,我不确定为什么它不能更早地工作。可能是我忽略了这个问题。 :)