How to loop through nested elements in tInputFileXML

One Star

How to loop through nested elements in tInputFileXML

Hi: I have an xml file that has nested child elements. All these child elements can have 1 and more occurrences. Can some one tell how to set the xpath loop expression for all these nested elements while creating the meta data.
Thanks,
RJ
Community Manager

Re: How to loop through nested elements in tInputFileXML

Hello RJ
Can you give us an example of you file and what are your expected result?
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to loop through nested elements in tInputFileXML

Hi: Shong, here is the trim down example. BTW In this example we have more than one occurrences of 2 elements named <oversight_info> and <primary_outcome> but just to let you know all the elements under root node <clinical_study> can have 0 to many occurrences, so during the job design phase we can not guess what elements can have more than 1 occurrences, and we want to get them all.
BTW one more thing not directly related to the this scenario, but a general question, what version (1.0 or 2.0) of XPATH Talend supports to extract the fields from File XML meta data wizard.
<?xml version="1.0" encoding="UTF-8"?>
<clinical_study rank="1">

<brief_title>Feasibility Study of Take-Home LAAM Medication - 3</brief_title>
<official_title>Feasibility Study of Take-Home LAAM Medication</official_title>
<source>National Institute on Drug Abuse (NIDA)</source>
<oversight_info>
<authority>United States: Federal Government</authority>
</oversight_info>
<oversight_info>
<authority>Germany: Federal Government</authority>
</oversight_info>
<primary_outcome>
<measure>Drug use</measure>
</primary_outcome>
<primary_outcome>
<measure>Retention</measure>
</primary_outcome>
<primary_outcome>
<measure>Increased prosocial behaviors</measure>
</primary_outcome>
<primary_outcome>
<measure>Decreased frequency of HIV related behavior</measure>
</primary_outcome>
<enrollment>0</enrollment>
<condition>Opioid-Related Disorders</condition>
<intervention>
<intervention_type>Drug</intervention_type>
<intervention_name>LAAM</intervention_name>
</intervention>
</clinical_study>
Community Manager

Re: How to loop through nested elements in tInputFileXML

Hello
BTW one more thing not directly related to the this scenario, but a general question, what version (1.0 or 2.0) of XPATH Talend supports to extract the fields from File XML meta data wizard.

We use version 1.0 to parse xml file.
but just to let you know all the elements under root node <clinical_study> can have 0 to many occurrences

<clinical_study> must be at leat 1 occurrences, so I think you should wirte some java code to parse the xml file and check it contains <clinical_study>node at the begging of job, if so, do the next processing, otherwise, do nothing.
BTW In this example we have more than one occurrences of 2 elements named <oversight_info> and <primary_outcome> but just to let you know all the elements

Using two tFileInputXML to set different loop xpath, <oversight_info> and <primary_outcome>, eg:
"/clinical_study/oversight_info"
"/clinical_study/primary_outcome"
and then merge all the records if needed.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

Re: How to loop through nested elements in tInputFileXML

For detailed explanation of reading and processing XML file with multiple nested loops visit the blog post
http://vikramtakkar.blogspot.in/2013/02/read-xml-having-multiple-nested-loops.html