Friday, November 15, 2013

In SOA, we use file adapter to read Non-XMl file and transform it to XML format but in OSB along with file adapter we also have MFL that we can use to transform Non-XML data to XML data.

We use Format Builder to create mfl files and we can't create mfl file from OSB console, we have to use OSB IDE (Eclipse) to create this mfl file.

In this post, I will show you how we can transform Non-XML data to XML data using MFL. To show this, we prepared one use case in which we will read tab delimited file and transform it to XML format and write to one location.

Tab Delimited File

1              Vivek      28           India
2              Garg       28           India

Final XML Format

<Customer >
<CustInfo>
<Id>1</Id>
<Name>Vivek</Name>
<Age>28</Age>
<Country>India<Country>
</CustInfo>
<CustInfo>
<Id>2</Id>
<Name>Garg</Name>
<Age>28</Age>
<Country>India<Country>
</CustInfo>
</Customer>

First of all, we will create mfl file from Format Builder. Follow below steps to create MFL file.

- Open Eclipse and create one OSB project. Create required folder structure and under mfl folder create new MFL file. Give it a name (Customer.mfl).




- Open above created mfl file and start building it. Whatever name you will give to mfl file name, that name will appear as first element in mfl. As "CustInfo" is the repeating tag so we will add a Group under Customer in Mfl, to do this right-click on Customer and click on Insert Group.




- Choose below options for CustInfo Group.



- Now add respective elements under CustInfo Group and all these element will be added as child of Group. Id, Age, Name elements are separated by tab.


 Another main point to note here is the Code Page, choose "UTF-8......." from dropdown.


- Country element/child is delimited by end of line so in delimiter mention \n.


- Below is the final structure.


Follow below steps to test above created MFL file.
 - Go to Tools --> Test.


- Put Non-XML data that we want to test in left pane and click on "Non-XML To XML" under Transform option.


-  You will see the final XML in right pane.



Follow Part-2 to see how we will use this MFL file in OSB project to transform Non-XML data to XML format.

0 comments :

Post a Comment