【发布时间】:2021-02-13 05:52:35
【问题描述】:
我有两个来自 DB 的结果集,一个在 Payload 中,另一个在另一个变量中。我正在尝试遍历多个结果集以形成 xml。在第二次迭代中,我需要从第二个结果集中获取多个实体标签。
有效载荷:
[
{
"Version": "1.0",
"ID": "VKP",
"Password": "VKP",
"Username": "VKP",
"id": "123456789",
"Amount": "1000",
"StreetAddress": "Oaks Ave"
}
]
vars.borrowerResult:
[
{
"firstname": "Vinoy",
"lastname" :"VKP"
},
{
"firstname": "Kevin",
"lastname" :"Peter"
}
]
当前代码:
%dw 2.0
output application/xml
fun StreetAddressSizeCheck(data) = if(data != null and sizeOf(data) > 30) data[0 to 29] else data
---
DRIVERequest @(version : "1.00") : {
Authentication @(ID : "*****", Password : "******", Username : "******") : null,
BatchRequest : payload map {
Mortgage @(id : $.id, Amount : $.Amount) : {
Property @(StreetAddress : StreetAddressSizeCheck($.StreetAddress)) : null,
//Below is the place i am trying to add the code to iterate over variabe.
// If there are multiple objects i need to get as much entries are there in Array.
vars.borrowerResult map{
Borrower @(firstname :$.firstname ,lastname : $.lastname) : null,
}
}
}
预期的 XML 输出是
<?xml version='1.0' encoding='UTF-8'?>
<DRIVERequest version="1.00">
<Authentication ID="*****" Password="******" Username="******"/>
<BatchRequest>
<Mortgage id="123456789" Amount="1000">
<Property StreetAddress="Oaks Ave"/>
<Borrower firstname="Vinoy" lastname="VKP"/>
<Borrower firstname="Kevin" lastname="Peter"/>
</Mortgage>
</BatchRequest>
</DRIVERequest>
【问题讨论】:
标签: xml dataweave mulesoft mule4