Standards and Best Practices: Export Tree Structure Data to CSV

I have tree structure data (parent child) to export to CSV.

Is there any standard format for displaying data in a meaningful way, and possibly for future use?

I am currently considering using the empty "" to indicate the next level.

+4
source share
1 answer

Well, there is no standard, at least not what I know about. This usually relates to aspects of performance, ease of use, and tree size.

I can suggest that you save the tree as a pair of parent-son relationships, and then you can recreate the tree.

Example:

Suppose you have a tree:

root

a b c 

This can be expressed as a series of relations:

root → a

root → b

 b --> c 

This is exactly what you can save in a file:

 root,a root,b b,c 

Another interesting method can be used taking into account the fact that a tree (at least a binary tree) can be represented as an array

This will allow you to save one line in your csv file, since the array is linear and naturally maps it to an array. I'm sure you can find many more ways to save the tree, the sky is the limit here, I just pointed you a few.

Hope this helps

+3
source

All Articles