Simbu
Simbu

Reputation: 796

ESB mule - Data Weaver transformation

I am new to mule esb. I am trying to fetch values from mySQL and transforming to XML. Then hitting service and then result will be stored back in DB table. I have two questions

1) I can see two different way of mapping in ESB mule. a) Using "Data Mapper" b) Using "Transform Message" - This will use data Weaver. Which one of the transformation method will suit for my requirement.

2) I tried using "Transform Message" and Data Weaver for transformation. My input from DB will fetch three rows as like below.

college = abc        college = abc        college = abc
dept = IT            dept = CSE           dept = MECH           
No of students = 5   No of students = 4   No of students = 7

Expected output is

<University>
<college>abc</college> <!-- this is simple tag/ It will not repeat -->
<dept> <!-- This is complex tag -->
   <dept Name>IT</dept Name>
   <No of students>5</No of students>
</dept>
<dept>
   <dept Name>IT</dept Name>
   <No of students>5</No of students>
</dept>
<dept>
   <dept Name>IT</dept Name>
   <No of students>5</No of students>
</dept>

I tried data weaver something like below.

%dw 1.0 

%output application/xml

"University":{
    "college": payload.college,
        dept: {
            dept_Name: payload."dept_Name",
            No of students: payload."No of students"
        }
}

But the above dw is not giving expected result. Could you please help me on this ?

Upvotes: 2

Views: 286

Answers (1)

sulthony h
sulthony h

Reputation: 1277

You can try this DataWeave, and modify as you need. Hope that helps.

%dw 1.0
%output application/xml
---
{
    University: {
        college: payload.college[0],
        (payload map ((payload01 , indexOfPayload01) -> {
            dept: {
                deptName: payload01.dept,
                Noofstudents: payload01."No of students" as :number
            }
        }))
    }
}

Upvotes: 2

Related Questions