简体   繁体   中英

Converting xml to json in dataweaver mule

I need to transform a file from xml to json. In my json file one field is a list of string which will take from Each line of xml. But I am not unale to do that in dataweaver of mule. Any help is appreciated. For reference I have posted the part of my xml and json file

XML

<lines>
<line id="MSK" in-voy-nbr="LP1" out-voy-nbr="LP1" />
<line id="MSC" in-voy-nbr="LP1" out-voy-nbr="LP1" />
<line id="HLC" in-voy-nbr="LP11" out-voy-nbr="" />
<line id="VIC" in-voy-nbr="LP1" out-voy-nbr="LP1" />
</lines>

JSON

{
"LINEOPERATORCODE": ["MSK", "MSC", "HLC", "VIC"]
}

You can try this:

%dw 1.0
%output application/json
---
{
    LINEOPERATORCODE: payload.lines.*line.@id
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM