code: def write_hypergraph(hgr):
      
  
      # Document root
      grxml = Document()
      grxmlr = grxml.createElement('hypergraph')
      grxml.appendChild(grxmlr)
  
      # Each node...
      nodes = hgr.nodes()
      hyperedges = hgr.hyperedges()
      for each_node in (nodes + hyperedges):
          if (each_node in nodes):
              node = grxml.createElement('node')
          else:
              node = grxml.createElement('hyperedge')
          node.setAttribute('id', str(each_node))
          grxmlr.appendChild(node)
  
          # and its outgoing edge
          if each_node in nodes:
              for each_edge in hgr.links(each_node):
                  edge = grxml.createElement('link')
                  edge.setAttribute('to', str(each_edge))
                  node.appendChild(edge)
  
      return grxml.toprettyxml()
docs: 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.