def write_hypergraph(hgr):
<EOL>grxml = Document()<EOL>grxmlr = grxml.createElement('<STR_LIT>')<EOL>grxml.appendChild(grxmlr)<EOL>nodes = hgr.nodes()<EOL>hyperedges = hgr.hyperedges()<EOL>for each_node in (nodes + hyperedges):<EOL><INDENT>if (each_node in nodes):<EOL><INDENT>node = grxml.createElement('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>node = grxml.createElement('<STR_LIT>')<EOL><DEDENT>node.setAttribute('<STR_LIT:id>', str(each_node))<EOL>grxmlr.appendChild(node)<EOL>if each_node in nodes:<EOL><INDENT>for each_edge in hgr.links(each_node):<EOL><INDENT>edge = grxml.createElement('<STR_LIT>')<EOL>edge.setAttribute('<STR_LIT:to>', str(each_edge))<EOL>node.appendChild(edge)<EOL><DEDENT><DEDENT><DEDENT>return grxml.toprettyxml()<EOL>
Return a string specifying the given hypergraph as a XML document.

@type  hgr: hypergraph
@param hgr: Hypergraph.

@rtype:  string
@return: String specifying the graph as a XML document.