Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Irshad1
Contributor II
Contributor II

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

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

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:

0683p000009LwUY.png

-You define your output structure as recursive

0683p000009LwDV.png

-In your map you create your loop:

0683p000009Lw9W.png

Regards.

 

Eric

View solution in original post

5 Replies
Anonymous
Not applicable

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:

0683p000009LwUY.png

-You define your output structure as recursive

0683p000009LwDV.png

-In your map you create your loop:

0683p000009Lw9W.png

Regards.

 

Eric

Anonymous
Not applicable

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.

Irshad1
Contributor II
Contributor II
Author

Thanks this works for me!

sreeraj
Contributor
Contributor

I know this is old thread, but I am having few levels being missed.
I followed the steps mentioned above.
I am attaching my input json and output json.any help is greatly appreciated. 


cpchinput.txt
cpchoutput.txt
Anonymous
Not applicable

Hi,

 

Could you add a sort function (It is probably expecting your levels are sorted in the input file):

0683p000009M8Rg.png

Regards

 

Eric