GraphML用于定义图形(graph),对于下面的一个简单图形,
用GraphML描述为:
<?xmlversion="1.0"encoding="UTF-8"?>
<graphmlxmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graphid="G"edgedefault="undirected">
<nodeid="n0"/>
<nodeid="n1"/>
<nodeid="n2"/>
<nodeid="n3"/>
<nodeid="n4"/>
<nodeid="n5"/>
<nodeid="n6"/>
<nodeid="n7"/>
<nodeid="n8"/>
<nodeid="n9"/>
<nodeid="n10"/>
<edgesource="n0"target="n2"/>
<edgesource="n1"target="n2"/>
<edgesource="n2"target="n3"/>
<edgesource="n3"target="n5"/>
<edgesource="n3"target="n4"/>
<edgesource="n4"target="n6"/>
<edgesource="n6"target="n5"/>
<edgesource="n5"target="n7"/>
<edgesource="n6"target="n8"/>
<edgesource="n8"target="n7"/>
<edgesource="n8"target="n9"/>
<edgesource="n8"target="n10"/>
</graph>
</graphml>
<graphmlxmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graphid="G"edgedefault="undirected">
<nodeid="n0"/>
<nodeid="n1"/>
<nodeid="n2"/>
<nodeid="n3"/>
<nodeid="n4"/>
<nodeid="n5"/>
<nodeid="n6"/>
<nodeid="n7"/>
<nodeid="n8"/>
<nodeid="n9"/>
<nodeid="n10"/>
<edgesource="n0"target="n2"/>
<edgesource="n1"target="n2"/>
<edgesource="n2"target="n3"/>
<edgesource="n3"target="n5"/>
<edgesource="n3"target="n4"/>
<edgesource="n4"target="n6"/>
<edgesource="n6"target="n5"/>
<edgesource="n5"target="n7"/>
<edgesource="n6"target="n8"/>
<edgesource="n8"target="n7"/>
<edgesource="n8"target="n9"/>
<edgesource="n8"target="n10"/>
</graph>
</graphml>
可以看出,GraphML中关于图形的一些基本概念如下:
需要注意以下几点:
<meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE"> <meta content="StarSuite 8 (Linux)" name="GENERATOR"> <meta content="*" name="AUTHOR"> <meta content="20071029;11490000" name="CREATED"> <meta content="Seaman Wang" name="CHANGEDBY"> <meta content="20080123;11091500" name="CHANGED"> <style type="text/css"> <!-- @page { size: 21cm 29.7cm; margin: 2cm } P { margin-bottom: 0.21cm } H4 { margin-bottom: 0.21cm } H4.western { font-family: "Thorndale", "Times New Roman", serif } H4.cjk { font-family: "方正宋体"; font-style: normal } H4.ctl { font-family: "Lucidasans" } PRE.western { font-family: "Cumberland", "Courier New", monospace } PRE.cjk { font-family: "方正宋体", monospace } PRE.ctl { font-family: "方正宋体", monospace } CODE.western { font-family: "Cumberland", "Courier New", monospace } CODE.cjk { font-family: "方正宋体", monospace } --> </style>
1.Graph中的元素(element)没有顺序要求
如,下面的Graph是正确的:
<graphid="G"edgedefault="directed">
<nodeid="n0"/>
<edgesource="n0"target="n2"/>
<nodeid="n1"/>
<nodeid="n2"/>
</graph>
<nodeid="n0"/>
<edgesource="n0"target="n2"/>
<nodeid="n1"/>
<nodeid="n2"/>
</graph>
Graph中必须指定
edgedefault
属性
(
“
directed”
或“
undirected”)
,
Edge
中也可以单独设置
directed
为
true
或
false
。