Crate petgraph_graphml[][src]

Expand description badge badge Rust CI codecov

This crate extends petgraph with GraphML output support.

This crate exports a single type GraphMl which combines a build-pattern for configuration and provides creating strings (GraphMl::to_string) and writing to writers (GraphMl::to_writer).


Add this to your Cargo.toml:

petgraph-graphml = "3.0.0"


For a simple graph like Graph with three nodes and two edges this is the generated GraphML output.

let graph = make_graph();
// Configure output settings
// Enable pretty printing and exporting of node weights.
// Use the Display implementation of NodeWeights for exporting them.
let graphml = GraphMl::new(&graph)

    r#"<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="">
  <graph edgedefault="directed">
    <node id="n0">
      <data key="weight">0</data>
    <node id="n1">
      <data key="weight">1</data>
    <node id="n2">
      <data key="weight">2</data>
    <edge id="e0" source="n0" target="n1" />
    <edge id="e1" source="n1" target="n2" />
  <key id="weight" for="node""weight" attr.type="string" />


GraphML output printer