简体   繁体   中英

Convert CSV to XML using Mule 4

Facing issues while converting CSV to XML using dataweave 2.0 in mule 4.

input payload (CSV):

employee_id,amount  
12345,75  
67890,15  
13579,38  

Output Result (XML):

<ch:Data xmlns:ch="xxx:com.abcdef.report">
  <ch:Entry>
     <ch:Employee_ID>12345</ch:Employee_ID>
     <ch:Cost>75</ch:Cost>
  </ch:Entry>
  <ch:Entry>
     <ch:Employee_ID>67890</ch:Employee_ID>
     <ch:Cost>15</ch:Cost>
  </ch:Entry>
  <ch:Entry>
     <ch:Employee_ID>13579</ch:Employee_ID>
     <ch:Cost>38</ch:Cost>
  </ch:Entry>
</ch:Data>

You need to use the dynamic object feature so that it expands the array in the parent object

%dw 2.0
ns ch xxx:com.abcdef.report
output application/xml
---
ch#Data: {
    (payload map {
        ch#Entry: {
            ch#Employee_ID: $.employee_id,
            ch#Cost: $.amount 
        }
    })
}

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