def write_hypergraph(hgr):
    """
    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.
    """

    # 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 nodes in each_node:
            for each_edge in hgr.links(each_node):
                edge = grxml.createElement('link')
                edge.setAttribute('to', str(each_edge))
                node.appendChild(edge)

    return grxml.toprettyxml()
dataset/ETHPy150Open pmatiello/python-graph/core/pygraph/readwrite/markup.py/write_hypergraph/swapped operands of `in`