This paper is published in the DZone
https://dzone.com/articles/remote-debugging-mule-applicationThursday, December 21, 2017
Mule Application Development: Effective Caching
This paper has been published at DZone:
Mule Application Development: Effective CachingSaturday, December 16, 2017
Mule Dev Tricks: Dataweave Working With XML Data
The Use Case
In my earlier post, I have explained the tricks using xpath3() to extract data from xml data. In this post I will demonstrate a use case to extract data using Dataweave.
Here is the input data (I omitted the not-interesting xml data:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ... < wd:email_address_data > < wd:email_address >anshul.gupta277@gmail.com</ wd:email_address > < wd:usage_data wd:public = "0" > < wd:type_data wd:primary = "1" > < wd:type_reference wd:descriptor = "Home" > < wd:id wd:type = "WID" >836cf00ef5974ac08b786079866c946f</ wd:id > < wd:id wd:type = "Communication_Usage_Type_ID" >HOME</ wd:id > </ wd:type_reference > </ wd:type_data > </ wd:usage_data > </ wd:email_address_data > < wd:email_address_data > < wd:email_address >sudeshna.nanda@tcs.com</ wd:email_address > < wd:usage_data wd:public = "1" > < wd:type_data wd:primary = "1" > < wd:type_reference wd:descriptor = "Work" > < wd:id wd:type = "WID" >1f27f250dfaa4724ab1e1617174281e4</ wd:id > < wd:id wd:type = "Communication_Usage_Type_ID" >WORK</ wd:id > </ wd:type_reference > </ wd:type_data > </ wd:usage_data > </ wd:email_address_data > ... |
The desired output is an arraylist:
1 2 3 4 5 6 7 8 9 10 11 12 | [ { email=anshul.gupta277@gmail.com, wid=836cf00ef5974ac08b786079866c946f, type=HOME }, { email=sudeshna.nanda@tcs.com, wid=1f27f250dfaa4724ab1e1617174281e4, type=WORK } ] |
The Solution
The following is the solution:1 2 3 4 5 6 7 8 9 10 | %dw 1.0 %output application/java %namespace ns0 urn:com.workday/bsvc --- payload.ns0#Get_Workers_Response.ns0#Response_Data.*ns0#Worker.ns0#Worker_Data.ns0#Personal_Data.ns0#Contact_Data.*ns0#Email_Address_Data map { email: $.ns0#Email_Address, wid: $.ns0#Usage_Data.ns0#Type_Data.ns0#Type_Reference.*ns0#ID[?($.@ns0#type == "WID")][0], type: $.ns0#Usage_Data.ns0#Type_Data.ns0#Type_Reference.*ns0#ID[?($.@ns0#type == "Communication_Usage_Type_ID")][0] } |
The Key Learning Points
- Make array with wildcard *: ns0#Contact_Data.*ns0#Email_Address_Data
- Get expect element using: ns0#ID[?($.@ns0#type == "WID")][0]
- Remember: access attribute of a xml element using @
Subscribe to:
Posts (Atom)
Anypoint Studio Error: The project is missing Munit lIbrary to run tests
Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...
-
Introduction MuleSoft has changed many stuff for the last year. One of the questions developer will ask is how to change the logging level....
-
Introduction The video for this blog is available at: http://www.youtube.com/watch?v=wVCmik-2xAM&feature=youtu.be Mule and JBoss ...
-
Congratulation Gary! First of all, I must congratulate myself for getting this done. For almost a year, I have been thinking to take the e...