Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

networkx.readwrite.graphml.generate_graphml

generate_graphml(G, encoding='utf-8', prettyprint=True, named_key_ids=False)[source]

Generate GraphML lines for G

Parameters
Ggraph

A networkx graph

encodingstring (optional)

Encoding for text data.

prettyprintbool (optional)

If True use line breaks and indenting in output XML.

named_key_idsbool (optional)

If True use attr.name as value for key elements’ id attribute.

Notes

This implementation does not support mixed graphs (directed and unidirected edges together) hyperedges, nested graphs, or ports.

Examples

>>> G = nx.path_graph(4)
>>> linefeed = chr(10)  # linefeed = 
>>> s = linefeed.join(nx.generate_graphml(G))
>>> for line in nx.generate_graphml(G):  
...     print(line)