Retrieve & Convert a CSV File to XML Using Data Mapper in WSO2

Retrieve & Convert a CSV File to XML Using Data Mapper in WSO2

Data Mapper in WSO2 provides a seamless solution for retrieving and converting CSV files to XML format. By utilizing this powerful tool, users can effortlessly map data from CSV files into structured XML format with ease and efficiency. This process not only streamlines data conversion but also enhances data integration capabilities within the WSO2 platform, ultimately saving time and resources for developers and organizations alike.

Data Mapper simplifies the transformation of data between CSV and XML formats, enabling users to easily handle complex data mapping requirements. With its user-friendly interface and robust functionality, WSO2’s Data Mapper empowers developers to efficiently manage data conversion tasks without the need for extensive manual intervention.

By leveraging this advanced tool, organizations can seamlessly sync data across different systems within the WSO2 platform, promoting seamless integration and facilitating smoother workflow processes. Embrace the power of WSO2’s Data Mapper for enhanced efficiency and optimal data management within your organization today!

Walkthrough

Create new project in Integration studio >> File >> New >>Integration project and give the Project name. 

Right-click on FileTransformationWithPollingConfigs and navigate to New >>Inbound Endpoint. Select Create a New Inbound Endpoint and click Next.

Enter the following details and click Finish.

Configure the Properties:

  • transport.vfs.ContentType: text/plain
  • transport.vfs.ActionAfterFailure: MOVE
  • transport.vfs.ActionAfterProcess: MOVE
  • transport.vfs.FileURI: file:///D:/samplecsv
  • transport.vfs.MoveAfterFailure: file:///D:/testing
  • transport.vfs.ReplyFileName: response.xml
  • transport.vfs.DistributedLock: false
  • transport.vfs.FileNamePattern:.*.csv
  • transport.vfs.MoveAfterProcess: file:///D:/Readcsv

Read the file from file:///D:/samplecsv mentioned in Transport VFS File URI

Move the file located at file:///D:/samplecsv to the destination folder file:///D:/Readcsv

Creating a Sequence Artifact

  • Right-click the ESB Config project and go to New → Sequence to open the New Sequence Artifact dialog box
  • Select Create New Sequence and click Next.
  • In the Save Sequence in field, specify the location to save the sequence.
  • Click Finish

Double-click the Success_Seq mediator to access and review the added logic.

  • Drag and drop the Log mediator to log information about messages or events passing through.Drag and drop the Data Mapper
  • Update required fields of Data Mapper mediator allows you to transform data between different formats within your integration flows.
  • Update Data Mapper Configurations as below
    • Configuration Name
    • Save in project.
    • Click on Ok

Input and output schema files:
The Data Mapper tool generates them when loading the input and output files.

Click on Load Input Field

  • Resource Type: CSV
  • Select resource from file system or registry or workspace.
  • Click on OK

Click on Load Output Field

  • Resource Type: XML
  • Select resource from file system or registry or workspace
  • Click on OK

Mapping CSV files to XML format

Double-click the Error_Seq mediator.

Drag and drop the Log mediator to log information about messages or events passing through.

Build and run the artifacts

  • Right- click  FileTransformationWithPollingCompositeExporter and click Export Project Artifacts and Run
  • You will see the following dialog box. Select the FileTransformationWithPollingConfigs folder in the artifact list and click Finish.

In the console the successful reading and movement of the file from one folder to another

The data has been successfully converted from CSV to XML file, as depicted in the picture.

<?xml version=’1.0′ encoding=’utf-8′?><soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”><soapenv:Body><catalog><book id=”Indexno”><author>Year</author></book><book id=”1″><author>2021</author></book><book id=”2″><author>2021</author></book><book id=”3″><author>2021</author></book><book id=”4″><author>2021</author></book><book id=”5″><author>2021</author></book><book id=”6″><author>2021</author></book><book id=”7″><author>2021</author></book><book id=”8″><author>2021</author></book><book id=”9″><author>2021</author></book></catalog></soapenv:Body></soapenv:Envelope>

The article has showcased how to retrieve and convert a CSV file to XML using Data Mapper in WSO2. For more information or queries on WSO2, please write to [email protected].