VinnyChinn
VinnyChinn

Reputation: 49

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>

Upvotes: 2

Views: 1202

Answers (1)

machaval
machaval

Reputation: 5059

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 
        }
    })
}

Upvotes: 4

Related Questions