'Serialize graph G in GraphML to the stream.'

def add_graph_element(self, G):

    if G.is_directed():
        default_edge_type = 'directed'
    else:
        default_edge_type = 'undirected'
    graphid = G.graph.pop('id', None)
    if (graphid is None):
        graph_element = self.myElement('graph', edgedefault=default_edge_type)
    else:
        graph_element = self.myElement('graph', edgedefault=default_edge_type, id=graphid)
    default = {}
    data = dict(((k, v) for (k, v) in G.graph.items() if (k not in ['node_default', 'edge_default'])))
    self.add_attributes('graph', graph_element, data, default)
    self.add_nodes(G, graph_element)
    self.add_edges(G, graph_element)
    for (xml_obj, data) in self.attributes.items():
        for (k, v, scope, default) in data:
            xml_obj.append(self.add_data(make_str(k), self.attr_type(k, scope, v), make_str(v), scope, default))
    self.xml.append(graph_element)
