Is there a library similar to xmltodict
for rust?
The gist of it is that it converts an xml document into a dictionary so that it "feels" like working with JSON. Additionally it supports roundtripping that dictionary back into the original XML document.
I like to use lib.rs to search for crates:
quick-xml
looks like the most popular XML parser implementation. They do have quite extensive documentation for parsing XML into Rust data types using serde. I don't have any experience with it.
3 Likes
You can parse xml into serde_json::Value
, which is similar to python values.
fn main() {
let input = r#"<a b="1"><c/>d</a>"#;
let value: serde_json::Value = serde_xml_rs::from_str(input).unwrap();
dbg!(value);
}
Output is
[src/main.rs:6:5] value = Object {
"$value": String("d"),
"b": String("1"),
"c": Object {},
}
2 Likes
serde_xml_rs looks like exactly what I need but unfortunately it seems like an unmaintained project.
It has an unresponsive maintainer unfortunately, but the library itself is okay.
1 Like