One Star

Merging of files using talend data mapper

Hi Guys,
Currently I have an issue which needs to  combine different segments of xml file into one  but unfortunately as we have multiples loops i cannot make use of txml map and thus will need to move to talend data mapper. Since this is something new for me, can anyone please share their experience regarding how we can perform this taking note that the data mapper can only have one input and thus cannot combine output from different txmlmap to it.
Thanks in advance.
9 REPLIES
Not applicable

Re: Merging of files using talend data mapper

Hi,
Please find enclosed a solution (I'm not sure I got your need right).
I have two input files:
<?xml version="1.0"?>
<POs>
<PO>
  <Number>1</Number>
  <Company>Oakland Software</Company>
</PO>
<PO>
  <Number>2</Number>
  <Company>Ohio Software</Company>
</PO>
</POs>
and
<?xml version="1.0"?>
<ORDERs>
<ORDER>
  <Number>3</Number>
  <Company>California Software</Company>
</ORDER>
<ORDER>
  <Number>4</Number>
  <Company>Alaska Software</Company>
</ORDER>
</ORDERs>
In output file, I will get PO number of first file with company name of second file. It doesn't make sense, it is just for tests...
I created two structures:
POs for the first file
ORDERS for the second one
Then I created a third structure called MULTI with a root element and two subelement that inherits from the stucture created previously. In these two element, I use the READURL function in I/O tab to assign the file to read.
Then I created a map called MULTI_PO with this MULTI structure as input. The output structure is POs (Once again it doesn't really make sense, it is just for the exercise).
Finally, I created a job READURL that runs the map with a tHmap component and write the output file in a tLogrow.
I enclosed the structures, map, and job.
READURL.zip
Let me know if it meets your requirements.
NB: when you run the map in data mapper in test mode, READURL function doesn't work, you have to run the map from a job.
Regards.
Eric 
One Star

Re: Merging of files using talend data mapper

Hi,
Thanks for your input.To be more specific, I have one main xml file which is a package and the other two xmls are part of the xml which needs to be grouped under the same package based on their id.
First XML:
<?xml version="1.0" encoding="UTF-8"?>
<Packagings>
<Packaging>
<ID>1234</ID>
<Codes>
<Code name="Type">QWE</Code>
</Codes>
</Classification>
</Packaging>
<Packaging>
<ID>456</ID>
<Classification>
<Codes>
<Code name="Type">RTY</Code>
</Codes>
</Classification>
</Packaging>
</Packagings>
Second xml:
<?xml version="1.0" encoding="UTF-8"?>
<Supports>
<Support>
<ID>asd123</ID>
<Specifications>
<Property>
<NameValue name="testval">1</NameValue>
</Property>
<Property>
<NameValue name="testval1">val2</NameValue>
</Property>
</Specifications>
<PackageID>1234</PackageID>
</Support>
<Support>
<ID>test56</ID>
<Specifications>
<Property>
<NameValue name="testval">14</NameValue>
</Property>
<Property>
<NameValue name="testval1">Val3</NameValue>
</Property>
</Specifications>
<PackageID>1234</PackageID>
</Support>
<Support>
<ID>wer123</ID>
<Specifications>
<Property>
<NameValue name="testval">1.3</NameValue>
</Property>
<Property>
<NameValue name="testval1">val2</NameValue>
</Property>
</Specifications>
<PackageID>456</PackageID>
</Support>
</Supports>
I will need to have the support under the package which it is related to.
can you please help how i can achive it using data mapper?
Thanks.
Not applicable

Re: Merging of files using talend data mapper

Hi,
Could you provide us (in your example) with the expected output file ?
Eric
One Star

Re: Merging of files using talend data mapper

Hi,
the expected output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Packagings>
    <Packaging>
        <ID>1234</ID>
        <Codes>
                <Code name="Type">QWE</Code>            
            </Codes>
        </Classification>
<Supports>
    <Support>
        <ID>asd123</ID>
        <Specifications>
            <Property>
                <NameValue name="testval">1</NameValue>
            </Property>
            <Property>
                <NameValue name="testval1">val2</NameValue>
            </Property>
        </Specifications>
        <PackageID>1234</PackageID>
    </Support>
        </Packaging>
    <Packaging>
        <ID>456</ID>
        <Classification>
            <Codes>
                <Code name="Type">RTY</Code>                
            </Codes>
        </Classification>  
<Support>
<ID>test56</ID>
<Specifications>
<Property>
<NameValue name="testval">14</NameValue>
</Property>
<Property>
<NameValue name="testval1">Val3</NameValue>
</Property>
</Specifications>

</Support>
        <Support>
<ID>wer123</ID>
<Specifications>
<Property>
<NameValue name="testval">1.3</NameValue>
</Property>
<Property>
<NameValue name="testval1">val2</NameValue>
</Property>
</Specifications>
        
</Support>
    </Packaging>
</Packagings>

Thanks a lot for your help.
One Star

Re: Merging of files using talend data mapper

Hi Sorry,
Please see correct expected output.
<?xml version="1.0" encoding="UTF-8"?>
<Packagings>
<Packaging>
<ID>1234</ID>
<Codes>
<Code name="Type">QWE</Code>
</Codes>
</Classification>
<Supports>
<Support>
<ID>asd123</ID>
<Specifications>
<Property>
<NameValue name="testval">1</NameValue>
</Property>
<Property>
<NameValue name="testval1">val2</NameValue>
</Property>
</Specifications>

</Support>
<Support>
<ID>test56</ID>
<Specifications>
<Property>
<NameValue name="testval">14</NameValue>
</Property>
<Property>
<NameValue name="testval1">Val3</NameValue>
</Property>
</Specifications>

</Support>
</Packaging>
<Packaging>
<ID>456</ID>
<Classification>
<Codes>
<Code name="Type">RTY</Code>
</Codes>
</Classification>
<Support>
<ID>wer123</ID>
<Specifications>
<Property>
<NameValue name="testval">1.3</NameValue>
</Property>
<Property>
<NameValue name="testval1">val2</NameValue>
</Property>
</Specifications>

</Packaging>
</Packagings>
Thanks again for your help Eric.
Not applicable

Re: Merging of files using talend data mapper

Hi,
Please find enclosed a solution    
PACKAGE_SO… .zip                                             
There are three maps:
MERGE_PACK (To merge both files according to packing ID) calls LOOP_PACK (Create a hierachy packaging) that calls FINAL_PACK (To get your expected output structure)
Job READ_URL calls map MERGE_PACK then write the output file on the file system.
Regards.
Eric
One Star

Re: Merging of files using talend data mapper

Thanks Eric. I will check your solution and revert back to you when if i need further help.
Thanks once again.
Regards,
Oodaye
One Star

Re: Merging of files using talend data mapper

Hi Eric,
I wanted to know if instead of reading from a file, how can we read directly from an output of a component using the data mapper?
Can you please advise?
Thanks.
Not applicable

Re: Merging of files using talend data mapper

Hi,
See tHmap component documentation (Second scenario)
Eric