[Blog Post] CSV to XML Transformation with WSO2 ESB Smooks Mediator

  • By Lakmali Erandi Baminiwatta
  • 3 Sep, 2013

Latest ESB can be downloaded from here.

We are going to transform the below CSV to an XML message.


This is the format of the XML output message.


First lets write the smooks configuration to transform above CSV to given XML message (smooks-csv.xml).


Now let's write a simple proxy service to take the CSV file as the input message and process through the smooks mediator. For that first you need to enable VFS transport sender and reciever.

Below is the service synapse configuration. Make sure to change the following parameters according to your file system. You can find more information about the parameters from here.

  • transport.vfs.FileURI
  • transport.vfs.MoveAfterProcess
  • transport.vfs.ActionAfterFailure

You have to make an ESB local entry with the key 'smooks-csv' and give path to smooks-csv.xml which we crated above. So in the smooks mediator above, we are loading the smooks config through the local entry key name (smooks-csv).

To perform the transformation, what you need to do is drop the input message file to transport.vfs.FileURI location. In the log, you can see the transformed message in XML!! Now you got the CSV message in XML in your synapse sequence. So you can perform any further mediation to this message such as send to some endpoint/database/file etc.

Source: https://blog.lakmali.com/2013/08/csv-to-xml-transformation-with-wso2-esb.html.