用XML描述图形

用XML描述图形,xml,graph,Xml,Graph,我有一张下图。 如何在XML文件中描述此图? 我考虑一些图元素的上一个和下一个元素的线性列表。最简单的方法是什么?有无数种方法。例如,如下所示: <graph> <nodes> <node type="box" id="n1" name="1"/> <node type="box" id="n2" name="2"/> <node type="box" id="n3" name="3"/> <

我有一张下图。

如何在XML文件中描述此图?
我考虑一些图元素的上一个和下一个元素的线性列表。最简单的方法是什么?

有无数种方法。例如,如下所示:

<graph>
  <nodes>
    <node type="box" id="n1" name="1"/>
    <node type="box" id="n2" name="2"/>
    <node type="box" id="n3" name="3"/>
    <node type="box" id="n4" name="4"/>
    <node type="box" id="n5" name="5"/>
    <node type="box" id="n6" name="6"/>
    <node type="box" id="n7" name="7"/>
    <node type="box" id="n8" name="8"/>
    <node type="box" id="n9" name="9"/>
    <node type="box" id="n10" name="10"/>
    <node type="box" id="n11" name="11"/>

    <node type="null" id="n12"/>
    <node type="null" id="n13"/>

    <node type="junction" id="n14"/>
    <node type="junction" id="n15"/>
    <node type="junction" id="n16"/>
    <node type="junction" id="n17"/>
    <node type="junction" id="n18"/>
    <node type="junction" id="n19"/>
  </nodes>
  <edges>
    <edge from="n12" to="n1"/>
    <edge from="n1" to="n14"/>
    <edge from="n14" to="n2"/>
    <edge from="n14" to="n3"/>
    <edge from="n2" to="n15"/>
    <edge from="n3" to="n15"/>
    <edge from="n15" to="n16"/>
    <edge from="n16" to="n4"/>
    <edge from="n16" to="n7"/>
    <edge from="n16" to="n8"/>
    <edge from="n4" to="n17"/>
    <edge from="n17" to="n5"/>
    <edge from="n17" to="n6"/>
    <edge from="n5" to="n18"/>
    <edge from="n6" to="n18"/>
    <edge from="n18" to="n19"/>
    <edge from="n7" to="n19"/>
    <edge from="n8" to="n9"/>
    <edge from="n9" to="n19"/>
    <edge from="n19" to="n10"/>
    <edge from="n10" to="n11"/>
    <edge from="n11" to="n13"/>
  </edges>
</graph>
点文件生成以下图片:

echo 'graph { rankdir=LR;' ;
open 1.xml ;
my $node_tally = count(/graph/nodes/node) ;

for my $node in /graph/nodes/node {
    if ($node/@type = 'box') {
        echo :s $node/@id '[label="' $node/@name '"]' ;
    } else {
        echo :s $node/@id
            '[style=invis,label="",fixedsize=true,height=0,width=0]' ;
    }
}

for my $edge in /graph/edges/edge {
    my $from = /graph/nodes/node[@id=$edge/@from] ;
    my $to   = /graph/nodes/node[@id=$edge/@to] ;
    echo :s '"' $from/@id '"' ' -- ' '"' $to/@id '"' ;
}

echo '}' ;