| Crates.io | petgraph-graphml |
| lib.rs | petgraph-graphml |
| version | 5.0.0 |
| created_at | 2018-05-13 20:38:50.642649+00 |
| updated_at | 2025-07-13 21:15:37.642287+00 |
| description | GraphML output support for petgraph |
| homepage | |
| repository | https://github.com/jonasbb/petgraph-graphml |
| max_upload_size | |
| id | 65229 |
| size | 46,991 |
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:
[dependencies]
petgraph-graphml = "5.0.0"
For a simple graph like
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)
.pretty_print(true)
.export_node_weights_display();
assert_eq!(
graphml.to_string(),
r#"<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns">
<graph edgedefault="directed">
<node id="n0">
<data key="weight">0</data>
</node>
<node id="n1">
<data key="weight">1</data>
</node>
<node id="n2">
<data key="weight">2</data>
</node>
<edge id="e0" source="n0" target="n1" />
<edge id="e1" source="n1" target="n2" />
</graph>
<key id="weight" for="node" attr.name="weight" attr.type="string" />
</graphml>"#
);
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.