quick-xml
High performance xml pull reader/writer.
The reader:
- is almost zero-copy (use of
Cow
whenever possible) - is easy on memory allocation (the API provides a way to reuse buffers)
- support various encoding, namespaces resolution, special characters.
Syntax is inspired by xml-rs.
Usage
[]
= "0.9.4"
extern crate quick_xml;
Example
Reader
use Reader;
use Event;
let xml = r#"<tag1 att1 = "test">
<tag2><!--Test comment-->Test</tag2>
<tag2>
Test 2
</tag2>
</tag1>"#;
let mut reader = from_str;
reader.trim_text;
let mut count = 0;
let mut txt = Vec new;
let mut buf = Vec new;
// The `Reader` does not implement `Iterator` because it outputs borrowed data (`Cow`s)
loop
Writer
use Writer;
use Reader;
use ;
use Cursor;
use iter;
let xml = r#"<this_tag k1="v1" k2="v2"><child>text</child></this_tag>"#;
let mut reader = from_str;
reader.trim_text;
let mut writer = new;
let mut buf = Vec new;
loop
let result = writer.into_inner.into_inner;
let expected = r#"<my_elem k1="v1" k2="v2" my-key="some value"><child>text</child></my_elem>"#;
assert_eq!;
Performance
Benchmarking is hard and the results depend on your input file and your machine.
Here on my particular file, quick-xml is around 50 times faster than xml-rs crate.
// quick-xml benches
test bench_quick_xml ... bench: 256,921 ns/iter (+/- 18,306)
test bench_quick_xml_escaped ... bench: 324,320 ns/iter (+/- 19,968)
test bench_quick_xml_namespaced ... bench: 396,318 ns/iter (+/- 23,663)
// same bench with xml-rs
test bench_xml_rs ... bench: 14,839,533 ns/iter (+/- 2,377,647)
For a feature and performance comparison, you can also have a look at RazrFalcon's choose-your-xml-rs.
Contribute
Any PR is welcomed!
License
MIT