xml - 用 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>
但是,它仍然没有捕获节点的位置和边缘的形状。
通过以下生成点文件的xsh脚本进行验证:
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 '}' ;
点文件生成以下图片:
推荐阅读
- javascript - 是否可以在 A-Frame 中的另一个 nunjuck 模板文字内创建一个 nunjuck 模板文字?
- walmart-api - 沃尔玛电子邮件验证未收到
- ios - 应用内购买:自动更新订阅流程
- python-3.x - 无效的语法错误:totals.setdefault(item,0) totals[item]+=rating[other][item]*sim
- python - argparse 子解析器无法识别
- ms-access - 将数据类型更改为长整数时出现 Access DB 注册表项临时问题
- css - Angular 6 主题:如何设置背景颜色并在整个应用程序中使用
- c++ - 解析时动态切换解析器
- r - 随机森林生存分析崩溃
- excel-formula - 合并excel中两列的数据,交替行