输入XML
<Address>
<Street>Street Line 1</Street>
<Street>Street Line 2</Street>
<Street>Street Line 3</Street>
<City>City</City>
<Postcode>0000</Postcode>
</Address>
输出XML必需
<DeliveryAddress>
<DA1>Street Line 1</DA1>
<DA2>Street Line 2</DA2>
<DA3>Street Line 3</DA3>
<City>City</City>
<Postcode>0000</Postcode>
</DeliveryAddress>
如何使用Dataweave将每个街道元素放入出站XML中的特定DA元素?
我尝试使用*通配符(地址。*街道)但是然后将街道元素作为子元素:
<DeliveryAddress>
<DA1>
<Street>Street 1</Street>
<Street>Street 2</Street>
<Street>Street 3</Street>
</DA1>
<City>City</City>
<Postcode>0000</Postcode>
</DeliveryAddress>
请帮助^ _ ^
答案 0 :(得分:1)
*通配符用于引用重复元素,尤其是XML格式。从这一点开始,我们可以顺序解决这个问题:
payload.Address.*Street
开始,我们将获得一个Street列表。(payload.Address.*Street)
,使其成为对象而不是数组。() or '' or ""
来包含输出: ("DA" ++ $$ + 1)
或"DA$($$ + 1)"
同样返回相同的结果:DA1,DA2,DA3,......
因此,此字段的完整表达式应为:(payload.Address.*Street map { ("DA" ++ $$ + 1): $ })
答案 1 :(得分:0)
基于Suthony输入,我刚刚在下面复制,你可以找到dwl脚本
%dw 1.0
是DeliveryAddress:{
(payload.Address.*Street map {
("DA" ++ $$ + 1): $
}),
city:payload.Address.City,
PostCode:payload.Address.Postcode
}
干杯!
答案 2 :(得分:0)
{
DeliveryAddress: {
(payload.Address.*Street map {
("DA" ++ $$ +1): $
}),
City: payload.Address.City,
Postcode: payload.Address.Postcode
}
}
("DA" ++ $$+1)
打印DA1,DA2等。