如何处理mule ESB中的响应

时间:2015-12-17 04:46:53

标签: mule-studio mule-component mel dataweave

我正在尝试编写数据编织以在响应xml中添加价格。

请求xml看起来像

<?xml version="1.0" encoding="UTF-8"?>
<UniversityResponse xmlns="urn:abc:api:Components">
    <Timestamp>2015-12-16T22:05:41.229Z</Timestamp>
    <Dept>IT</Dept>
    <Fees>
        <Fee>
            <Name>John</Name>
            <Fee currencyID="USD">1.0</Fee>
        </Fee>
        <Fee>
            <Name>Enrique</Name>
            <Fee currencyID="USD">3.0</Fee>
        </Fee>
        <Fee>
            <Name>Mary</Name>
            <Fee currencyID="USD">2.0</Fee>
        </Fee>
        <Fee>
            <Name>Meena</Name>
            <Fee currencyID="USD">0.5</Fee>
        </Fee>
    </Fees>
</UniversityResponse>

截至目前我写的像

%dw 1.0
%namespace ns0 urn:abc:api:Components
%output application/xml
---
TotalFees:{
    plus : payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[0].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[0].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[1].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[2].ns0#Fee +
    payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee[3].ns0#Fee 
}

输出:

<TotalFees>
  <plus>6.5</plus>
</TotalFees>

如何在响应xml中循环复杂标记?

基本上我想为UniversityResponse / Fees创建一个循环。在循环内部我想写一些类似Plus = Plus +“UniversityResponse /费用/费用[柜台] .Fee”

1 个答案:

答案 0 :(得分:1)

这是一种破解者,因为我在文档中寻找SUM函数,而不是在文档中,但它在语言中:)

-

%dw 1.0
%output application/xml
%namespace ns0 urn:abc:api:Components
---

TotalFees: plus: sum payload.ns0#UniversityResponse.ns0#Fees.*ns0#Fee.ns0#Fee
<?xml version='1.0' encoding='UTF-8'?>
<TotalFees>
  <plus>6.5</plus>
</TotalFees>