Xml – Representing a graph in XML

graphxml

Hi what will the best possible way to represent a graph in XML, where a node can be the child of a parent node and may be the parent of another child node. It can refer to itself, and multiple nodes can have same parent. And a node can have multiple parents.
All nodes are from same class. I want to build it efficiently, so that if I can learn about a child node from a parent node I can go to the specific child tag without having to iterate all the nodes. Is it possible?
for example here is an overview,

A->B,C,D

B->C,D

it may look like

<Node name=A>
 <childNode name=B>
 <childNode name=C>
 <childNode name=D>
</Node>

<Node name=B>
 <childNode name=C>
 <childNode name=D>
</Node>

So are there any better approaches than this? Whenever I get a child from A i.e. B, than I will have to basically iterate through all Nodes and match there name attribute with B to find the Node that represents B. Can I somehow do it faster?

Best Answer

Since you have a graph, and not a tree as you first thought, why not use 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.

Related Topic