您好,用 XML 表示图形的最佳方式是什么,其中节点可以是父节点的子节点,也可以是另一个子节点的父节点。它可以引用自己,多个节点可以有相同的父节点。一个节点可以有多个父节点。 所有节点都来自同一类。我想高效地构建它,这样如果我可以从父节点了解子节点,我就可以转到特定的子标记,而不必遍历所有节点。是否可以? 例如这里是一个概述,
A->B,C,D
B->C,D
看起来像
<Node name=A>
<childNode name=B>
<childNode name=C>
<childNode name=D>
</Node>
<Node name=B>
<childNode name=C>
<childNode name=D>
</Node>
那么还有比这更好的方法吗?每当我从 A 即 B 得到一个 child 时,我将不得不基本上遍历所有节点并将那里的名称属性与 B 匹配以找到代表 B 的节点。我能以某种方式更快地完成吗?
最佳答案
既然你有一个图,而不是你最初想的一棵树,为什么不使用 GraphML ?
GraphML is a comprehensive and easy-to-use file format for graphs. It consists of a language core to describe the structural properties of a graph and a flexible extension mechanism to add application-specific data.
Unlike many other file formats for graphs, GraphML does not use a custom syntax. Instead, it is based on XML and hence ideally suited as a common denominator for all kinds of services generating, archiving, or processing graphs.
关于xml - 用 XML 表示图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12905230/