Expand description
§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 graphml::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 (nodes, edges) = parse_graphml(input)?;
assert_eq!(nodes[0].id, "alice");
assert_eq!(nodes[0].labels, ["Person"]);
assert_eq!(nodes[0].properties[0].name, "age");
assert_eq!(nodes[0].properties[0].type_hint.as_deref(), Some("int"));
assert_eq!(edges[0].label, "KNOWS");§Streaming large documents
use graphml::{GraphmlReader, GraphmlRecord};
let input = r#"<graphml><graph><node id="a"/><edge source="a" target="a" label="SELF"/></graph></graphml>"#;
let mut edges = 0;
for record in GraphmlReader::new(input.as_bytes()) {
if let GraphmlRecord::Edge(_) = record? {
edges += 1;
}
}
assert_eq!(edges, 1);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.
Structs§
- Edge
- A GraphML
<edge>. - Graphml
Reader - Streams
<node>and<edge>records out of a GraphML document as it is read. Memory is bounded by the<key>table plus one element. - Node
- A GraphML
<node>. - Property
- One
<data>value with the declared key’s name and type.
Enums§
- Graphml
Error - Errors from parsing GraphML documents.
- Graphml
Record - One completed
<node>or<edge>. - KeyDomain
- Which elements a
<key>applies to (forattribute). - KeyType
- The declared
attr.typeof a<key>.
Functions§
- parse_
graphml - Parse a complete GraphML document into its nodes and edges.
- parse_
graphml_ with - Parse a complete GraphML document, invoking
on_node/on_edgefor each record as it completes.