GraphML
GraphML is an XML-based file format for serializing graphs — the structure of nodes and edges that make up a graph — together with any data attached to them. It emerged from the graph drawing community as a common interchange format, so that tools for layout, analysis, and visualization could exchange graph structures without each inventing a private notation. The format is defined by an XML schema and described in the Handbook of Graph Drawing and Visualization.
A GraphML document is an XML file whose root graphml element contains one or
more graph elements. Each graph holds an unordered sequence of node and
edge elements. Every node carries a distinct id, and every edge names
its endpoints through source and target attributes that refer to those ids.
The edgedefault attribute on the graph element declares whether edges are
directed, undirected, or mixed, and individual edges can override the default.
A minimal undirected graph with two nodes and one edge looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph id="G" edgedefault="undirected">
<node id="n0"/>
<node id="n1"/>
<edge id="e1" source="n0" target="n1"/>
</graph>
</graphml>Beyond the bare skeleton, GraphML was designed to cover the full range of graph
structures that turn up in practice. A graph can be nested, with a graph
element appearing inside a node to model hierarchy. Nodes can expose port
elements that edges attach to instead of the node itself, and hyperedges, which
connect more than two endpoints, have their own element. Application-specific
data such as weights, labels, coordinates, or colors is attached to nodes,
edges, ports, or the graph as a whole through key declarations paired with
data elements. That pairing is what makes GraphML extensible without changes
to the schema.
This expressiveness is the main reason GraphML is favored as an interchange format rather than a hand-edited one. It is verbose, like any XML format, and the schema’s machinery for nesting, ports, and typed data adds ceremony that a plain text format avoids. For human-authored graphs, simpler notations such as Trivial Graph Format (TGF) or Graph Modelling Language (GML) are easier to write. GraphML’s strength is fidelity. A tool that exports a GraphML file can capture directed and undirected edges, nested subgraphs, hyperedges, and arbitrary attribute data in a single document, and a conforming reader can reconstruct them. The name also invites confusion with GML, but the two are distinct formats with different syntax and lineage.
GraphML is widely supported across the graph tooling ecosystem. Editors such as yEd use it as their native format, and analysis and visualization tools including Gephi, Cytoscape, and NetworkX can import and export it. Many graph databases offer GraphML import and export for moving graphs in and out of a store, and it is a common serialization for exchanging knowledge graph data between tools.
See also
- Graph Modelling Language (GML)
- Trivial Graph Format (TGF)
- Graph databases
- Knowledge graph
- Directed acyclic graph (DAG)
- Vega
References
- Brandes, Ulrik; Eiglsperger, Markus; Lerner, Jürgen; Pich, Christian (2013). Graph Markup Language (GraphML). In Tamassia, Roberto (ed.), Handbook of Graph Drawing and Visualization. CRC Press. pp. 517–541.