XML Reformat

Hi,

Can anyone explain how XML reformat is being used to generate XML file.

Please let me know with one example.

Suppose we have three records in the input file as below:

XXX,001,Company_1
YYY,008,Company_2
zzz,002,Company_3
PPP,006,Company_2

where

XXX- name
001 - Emp Id
Company_1 - Company name

Can anyone help me out to explain the generation of XML using this example.

Questions by know_know   answers by know_know

Showing Answers 1 - 1 of 1 Answers

srihari_vsn

  • Jun 20th, 2011
 

Hi,

Let the input file data be as below.

PPP,006,Company_2
XXX,001,Company_1
YYY,008,Company_2
zzz,002,Company_3

Let the record format for reading this data be as below.


record
string(",") Name;
decimal(",") Employee_Id;
string("n") Employee_Name;
end;

Now add the XML Reformat component after the input file and in its transform function write down the below code.



out::reformat(in) =
begin
xml_begin_document("Employee");
xml_begin_element("Name");
xml_add_cdata(string_trim(in.Name));
xml_end_element();
xml_begin_element("Employee_Id");
xml_add_cdata(string_trim(in.Employee_Id));
xml_end_element();
xml_begin_element("Employee_Name");
xml_add_cdata(string_trim(in.Employee_Name));
xml_end_element();
xml_end_document();
out.XML_DATA:: xml_format();
end;


The output field will be only one for the reformat component i.e XML_DATA.
place an output file to capture all the 4 input records as 4 output records in xml format.
Output will be as below.

XML_DATA
<Employee><Name>XXX</Name><Employee_Id>001</Employee_Id><Employee_Name>Company_1</Employee_Name></Employee>
<Employee><Name>YYY</Name><Employee_Id>008</Employee_Id><Employee_Name>Company_2</Employee_Name></Employee>
<Employee><Name>zzz</Name><Employee_Id>002</Employee_Id><Employee_Name>Company_3</Employee_Name></Employee>
<Employee><Name>PPP</Name><Employee_Id>006</Employee_Id><Employee_Name>Company_2</Employee_Name></Employee>

Hope this helps.

Thanks.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions