简体   繁体   English

标准和最佳实践:将树结构数据导出为CSV

[英]Standards and Best practice: Exporting Tree Structure Data to CSV

I have a tree structural data(parent child) to export into CSV. 我有一个树结构数据(父子)导出到CSV。

Is there any standard format to display the data in a meaningful way and maybe for future usage? 是否有任何标准格式以有意义的方式显示数据,并可能用于将来的使用?

Currently I am considering using empty "", to denote the next level. 目前我正在考虑使用空“”来表示下一个级别。

Well, there is no standard here, at least not something I'm aware of. 嗯,这里没有标准,至少不是我所知道的。 It usually comes to performance aspects, the ease of usage and the size of tree. 它通常涉及性能方面,易用性和树的大小。

I can offer you to store the tree as a pairs of parent son relation, and then you'll be able to recreate the tree. 我可以提供您将树存储为一对父子关系,然后您将能够重新创建树。

Example: 例:

Lets assume, you have a tree: 让我们假设你有一棵树:

root

a

b

  c

This can be expressed like series of relations: 这可以表达为一系列关系:

root --> a root - > a

root --> b root - > b

b --> c

This is exactly what you can store in the file: 这正是您可以存储在文件中的内容:

root,a
root,b
b,c

Another interesting method can be used given the fact that the tree (at least binary tree) can be represented as an array 考虑到树(至少二叉树)可以表示为数组的事实,可以使用另一种有趣的方法

This will let you store the single line in your csv file since the array is linear and it naturally maps into an array I'm sure you can find much more ways to store the tree, the sky is a limit here, I've just pointed you a few. 这将允许您将单行存储在csv文件中,因为数组是线性的,它自然地映射到数组我相信你可以找到更多的存储树的方法,天空是一个限制,我只是你指了几个。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM