1 """Generate GraphXML documents suitable for hypergraph.
3 See http://hypergraph.sf.net for details about GraphXML.
7 open('data.xml', 'w').write(
8 graphxml.PrintDigraph(subgraph, 'Influence').toprettyxml())
11 import xml
.dom
.minidom
as dom
13 def PrintDigraph(graph
, name
):
14 d
= dom
.getDOMImplementation()
15 doctype
= d
.createDocumentType("GraphXML", "", "GraphXML.dtd")
16 doc
= d
.createDocument("", "GraphXML", doctype
)
17 graph_node
= doc
.documentElement
.appendChild(doc
.createElement("graph"))
18 graph_node
.setAttribute("id", name
)
19 for node_name
in graph
:
20 node
= graph_node
.appendChild(doc
.createElement("node"))
21 node
.setAttribute("name", node_name
)
22 label_node
= node
.appendChild(doc
.createElement("label"))
23 label_node
.appendChild(doc
.createTextNode(node_name
))
25 for a
, b
in graph
.iteritems():
26 edge
= graph_node
.appendChild(doc
.createElement("edge"))
27 edge
.setAttribute("source", a
)
28 edge
.setAttribute("target", b
)
29 edge
.setAttribute("isDirected", "true")