One Star

Header-Detail XML

How to design a job to process Header-Detail XML
1) I got an XML and the structure is as mentioned below.
<DATA>
<HEADER>
<UNIT_CODE></UNIT_CODE>
<COMPANY_CODE></COMPANY_CODE>
<BRANCH_CODE></BRANCH_CODE>
</HEADER>
<DETAILS>
<ITEM>
<ITEM_ID>true</ITEM_ID>
<ITEM_NAME>Jan</ITEM_NAME>
<ITEM_PRICE>Jan</ITEM_PRICE>
<DATE></DATE>
<CUSTOMER_NAME></CUSTOMER_NAME>
</ITEM>
<ITEM>
<ITEM_ID>true</ITEM_ID>
<ITEM_NAME>Jan</ITEM_NAME>
<ITEM_PRICE>Jan</ITEM_PRICE>
<DATE></DATE>
<CUSTOMER_NAME></CUSTOMER_NAME>
</ITEM>
<ITEM>
<ITEM_ID>true</ITEM_ID>
<ITEM_NAME>Jan</ITEM_NAME>
<ITEM_PRICE>Jan</ITEM_PRICE>
<DATE></DATE>
<CUSTOMER_NAME></CUSTOMER_NAME>
</ITEM>
</DETAILS>
</DATA>
Can we read all the data from the XML file using a single tFileInputXML?
Any body is having idea about this. Please help.
Thanks and Regards,
Pravu Mishra
6 REPLIES
One Star

Re: Header-Detail XML

Hello Pravu,
yes, it is possible to read all data from the XML file. create a metadata file for your XML file and use it in your job. refer this link for reference http://talendforge.org/forum/viewtopic.php?id=4074 .. if you are not getting anything after referred that, please post a message. i'll try to help you.
One Star

Re: Header-Detail XML

Hi Geetha,
Thanks for your prompt reply.
I went through the URL you have provided.
But thing is that , my XML file contains two type of records in it. One is a header record and a detail record.
Can we use a single tFileInputXML and read all the records of both the types. Please advice.
In case we can not do then what are the other ways we can use to transfer data from that XML file.
Thanks and Regards,
Pravu Mishra.
One Star

Re: Header-Detail XML

Hello Mishra,
as i said before, it is possible to read your XML records fully. actually what you wanna do after reading the XML data?
by using single tFileInputXML we could read the header & details record. but for each & every details record, header records will be taken, as we defined only one metadata file.
if you wanna take only once of header data, you need to define two metadata files. one for Header & another for Details.
use two tFileInputXML.
for example.,

tFileInputXML_1 -- row1(Main) --> tLogRow_1
|
OnSubJobOK
|
tFileinputXML_2 -- row2(Main) -- > tLogRow_2
try this. for tFileInputXMl_1, use header metadata & for tFileInputXML_2, use details metadata.
still you have any doubts or run into any issues, post the message. i'll try to clarify that. because am also a newbie to TOS. now only am also learning.
One Star

Re: Header-Detail XML

Geetha,
Thanks for your reply. I need to use only one tFileInputXML. Could you please provide me some idea.
Thanks and Regards,
Pravu Mishra.
One Star

Re: Header-Detail XML

Mishra,
really no idea.. upto my knowledge in TOS, if you try to use one tFileInputXML, there is two choice.. first one is, you can define metadata for header. but you cannot loop it for details, as root element is header. in this case you can read only one set of records of details data. second is, you can define a metadata for details, but here for each iteration of details records, header data will be taken.. but i'll try my level best. i need atleast 2 days time.
One Star

Re: Header-Detail XML

Hi Mishra,
as geetha wrote, if you would like to have only one tFileInputXML than you have to use his second choice. To get only the header data you can split them off in a tMap and use a tUniqueRow to get only the header at all.
Bye
Volker