mule 中的 dataweave 1.0 到 2.0 迁移

dataweave 1.0 to 2.0 migration in mule

尝试将下面的 dataweave 从 1.0 转换为 2.0,但我尝试过的所有操作都会出现以下错误,例如

SkipNullon shows error

Usage of Namespacing is not accepted,

@PostalCode[0..4] is not valid and

can't access the value inside insuredInfo using insuredPrimaryAddr.

Dataweave 1.0:

%dw 1.0
%output application/xml skipNullOn="everywhere"
%var insuredInfo = payload.DTOApplication.DTOInsured
%var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
%namespace ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0..4] default ""
}

我试过 Dataweave 2.0:

%dw 2.0
output application/xml skipNullOn="everywhere"
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
namespace ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0..4] default ""
}

有效负载:https://github.com/Manikandan99/rate-dtostep/blob/master/response.xml

关于如何在 dataweave 2.0 中编写相同的内容有什么想法吗?

在 dataweave 2.0 中,我们使用 to 运算符进行数组索引。

%dw 2.0
output application/xml skipNullOn="everywhere"
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
ns ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0 to 4] default ""
}

输出

<?xml version='1.0' encoding='windows-1252'?>
<ns0:rate xmlns:ns0="http://decisionresearch.com/RateMaker">
  <ns0:ZipCode>80003</ns0:ZipCode>
</ns0:rate>