3 releases
Uses old Rust 2015
0.1.2 | Apr 4, 2018 |
---|---|
0.1.1 | Apr 4, 2018 |
0.1.0 | Feb 8, 2017 |
#15 in #json-xml
10KB
183 lines
node2object
Convert between XML nodes (treexml) and JSON objects (serde-json).
Example
extern crate treexml;
#[macro_use]
extern crate serde_json;
extern crate node2object;
fn main() {
let dom_root = treexml::Document::parse("
<population>
<entry>
<name>Alex</name>
<height>173.5</height>
</entry>
<entry>
<name>Mel</name>
<height>180.4</height>
</entry>
</population>
".as_bytes()).unwrap().root.unwrap();
assert_eq!(serde_json::Value::Object(node2object::node2object(&dom_root)), json!(
{
"population": {
"entry": [
{ "name": "Alex", "height": 173.5 },
{ "name": "Mel", "height": 180.4 }
]
}
}
));
}
lib.rs
:
Convert between XML nodes (treexml) and JSON objects (serde-json).
Example
extern crate treexml;
#[macro_use]
extern crate serde_json;
extern crate node2object;
fn main() {
let dom_root = treexml::Document::parse("
<population>
<entry>
<name>Alex</name>
<height>173.5</height>
</entry>
<entry>
<name>Mel</name>
<height>180.4</height>
</entry>
</population>
".as_bytes()).unwrap().root.unwrap();
assert_eq!(serde_json::Value::Object(node2object::node2object(&dom_root)), json!(
{
"population": {
"entry": [
{ "name": "Alex", "height": 173.5 },
{ "name": "Mel", "height": 180.4 }
]
}
}
));
}
Dependencies
~3.5–5MB
~98K SLoC