graphml
A streaming GraphML parser that yields owned property-graph nodes and edges one element at a time.
<key>declarations are honoured: every<data>resolves to its key'sattr.nameandattr.type(kept as a type hint), and an undeclared key is an error rather than a silent drop.- Labels come from a key named
label/labels(Neo4j's:Person:Employeespelling and;/,separators are all split), or from an edge'slabelattribute. - Hierarchical GraphML (a
<graph>nested in a<node>) is tolerated: the outer node is emitted, nested content is skipped. - Memory is bounded by the key table plus one open element, however large
the document. Built on
quick-xml; atokiofeature addsAsyncGraphmlReaderover anyAsyncBufRead.
The crate depends on no database driver, graph store, RDF model, or
application framework. The optional property-graph-model feature adds
field-for-field From conversions into that crate's PgNode / PgEdge.
Quick start
use parse_graphml;
let input = r#"<graphml>
<key id="labels" for="node" attr.name="labels"/>
<key id="age" for="node" attr.name="age" attr.type="int"/>
<graph edgedefault="directed">
<node id="alice"><data key="labels">:Person</data><data key="age">30</data></node>
<node id="bob"><data key="labels">:Person</data></node>
<edge source="alice" target="bob" label="KNOWS"/>
</graph>
</graphml>"#;
let = parse_graphml?;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
# Ok::
Streaming large documents
use ;
let input = r#"<graphml><graph><node id="a"/><edge source="a" target="a" label="SELF"/></graph></graphml>"#;
let mut edges = 0;
for record in new
assert_eq!;
# Ok::
With the tokio feature, AsyncGraphmlReader::new(reader).next_record().await
does the same over an AsyncBufRead.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.