Six Stars

Talend Data Mapper : FlatToHeirarchyLoop

Hello All 

 

I'm working to TDM to generate XML which contain multiple hierarchy looping. I wanted to try the FlatToHeirarchyLoop  as the source is coming from Database. Can someone please help me in getting few examples of this type of loop?

Any help is appreciated.

 

Thanks!

Irshad

2 ACCEPTED SOLUTIONS

Accepted Solutions
Eight Stars

Re: Talend Data Mapper : FlatToHeirarchyLoop

Hi,

 

Prerequesite is to have a field in your input file with level hierarchy. If not, you cannot use this kind of loop.

 

Here is an example:
-Your input file is:
<records>
<record>
<level>1</level>
<unitid>0001</unitid>
</record>
<record>
<level>2</level>
<unitid>0002</unitid>
</record>
<record>
<level>3</level>
<unitid>0003a</unitid>
</record>
<record>
<level>3</level>
<unitid>0003b</unitid>
</record>
<record>
<level>3</level>
<unitid>0003c</unitid>
</record>
<record>
<level>1</level>
<unitid>0004</unitid>
</record>
</records>

 

-You want to get this output file:
<Root>
<Record level="1">
<level>1</level>
<unitid>0001</unitid>
<Record level="2">
<level>2</level>
<unitid>0002</unitid>
<Record level="3">
<level>3</level>
<unitid>0003a</unitid>
</Record>
<Record level="3">
<level>3</level>
<unitid>0003b</unitid>
</Record>
<Record level="3">
<level>3</level>
<unitid>0003c</unitid>
</Record>
</Record>
</Record>
<Record level="1">
<level>1</level>
<unitid>0004</unitid>
</Record>
</Root>

 

-You define your input structure:

Capture.PNG

-You define your output structure as recursive

Capture.PNG

-In your map you create your loop:

Capture.PNG

Regards.

 

Eric

Employee

Re: Talend Data Mapper : FlatToHeirarchyLoop

Just to clarify, the level number determines the depth of where to go in the output hierarchy. It's typically used with a recursive output hierarchy as Eric points out.

3 REPLIES
Eight Stars

Re: Talend Data Mapper : FlatToHeirarchyLoop

Hi,

 

Prerequesite is to have a field in your input file with level hierarchy. If not, you cannot use this kind of loop.

 

Here is an example:
-Your input file is:
<records>
<record>
<level>1</level>
<unitid>0001</unitid>
</record>
<record>
<level>2</level>
<unitid>0002</unitid>
</record>
<record>
<level>3</level>
<unitid>0003a</unitid>
</record>
<record>
<level>3</level>
<unitid>0003b</unitid>
</record>
<record>
<level>3</level>
<unitid>0003c</unitid>
</record>
<record>
<level>1</level>
<unitid>0004</unitid>
</record>
</records>

 

-You want to get this output file:
<Root>
<Record level="1">
<level>1</level>
<unitid>0001</unitid>
<Record level="2">
<level>2</level>
<unitid>0002</unitid>
<Record level="3">
<level>3</level>
<unitid>0003a</unitid>
</Record>
<Record level="3">
<level>3</level>
<unitid>0003b</unitid>
</Record>
<Record level="3">
<level>3</level>
<unitid>0003c</unitid>
</Record>
</Record>
</Record>
<Record level="1">
<level>1</level>
<unitid>0004</unitid>
</Record>
</Root>

 

-You define your input structure:

Capture.PNG

-You define your output structure as recursive

Capture.PNG

-In your map you create your loop:

Capture.PNG

Regards.

 

Eric

Employee

Re: Talend Data Mapper : FlatToHeirarchyLoop

Just to clarify, the level number determines the depth of where to go in the output hierarchy. It's typically used with a recursive output hierarchy as Eric points out.

Six Stars

Re: Talend Data Mapper : FlatToHeirarchyLoop

Thanks this works for me!