Represents an XML 1.0 document as a read-only tree.
Because in some cases all you need is to retrieve some data from an XML document. And for such cases, we can make a lot of optimizations.
As for roxmltree, it's fast not only because it's read-only, but also because it uses [xmlparser], which is many times faster than [xml-rs]. See the Performance section for details.
Sadly, XML can be parsed in many different ways. roxmltree tries to mimic the behavior of Python's lxml. But unlike lxml, roxmltree does support comments outside the root element.
Fo more details see docs/parsing.md.
| Feature/Crate | roxmltree | [libxml2] | [xmltree] | [elementtree] | [sxd-document] | [treexml] | | ------------------------------- | :--------------: | :-----------------: | :--------------: | :--------------: | :--------------: | :--------------: | | Element namespace resolving | ✔ | ✔ | ✔ | ✔ | ~1 | | | Attribute namespace resolving | ✔ | ✔ | | | ✔ | | | [Entity references] | ✔ | ✔ | ⚠ | ⚠ | ⚠ | ⚠ | | [Character references] | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | [Attribute-Value normalization] | ✔ | ✔ | | | | | | Comments | ✔ | ✔ | | | ✔ | | | Processing instructions | ✔ | ✔ | ⚠ | | ✔ | | | UTF-8 BOM | ✔ | ✔ | ⚠ | ⚠ | ⚠ | ⚠ | | Non UTF-8 input | | ✔ | | | | | | Complete DTD support | | ✔ | | | | | | Position preserving2 | ✔ | ✔ | | | | | | HTML support | | ✔ | | | | | | Tree modification | | ✔ | ✔ | ✔ | ✔ | ✔ | | Writing | | ✔ | ✔ | ✔ | ✔ | ✔ | | No unsafe | ✔ | | ✔ | ~3 | | ✔ | | Language | Rust | C | Rust | Rust | Rust | Rust | | Size overhead4 | ~73KiB | ~1.4MiB5 | ~80KiB | ~96KiB | ~135KiB | ~110KiB | | Dependencies | 1 | ?5 | 2 | 18 | 2 | 14 | | Tested version | 0.6.0 | 2.9.8 | 0.8.0 | 0.5.0 | 0.3.0 | 0.7.0 | | License | MIT / Apache-2.0 | MIT | MIT | BSD-3-Clause | MIT | MIT |
Legend:
Notes:
string_cache
crate.```text test largeroxmltree ... bench: 5,660,398 ns/iter (+/- 104,723) test largesdxdocument ... bench: 9,562,290 ns/iter (+/- 45,585) test largexmltree ... bench: 32,797,800 ns/iter (+/- 134,016) test largetreexml ... bench: 31,380,063 ns/iter (+/- 71,732) test largeelementtree ... bench: 32,121,979 ns/iter (+/- 264,842)
test mediumroxmltree ... bench: 1,094,562 ns/iter (+/- 6,030) test mediumsdxdocument ... bench: 3,791,252 ns/iter (+/- 41,929) test mediumtreexml ... bench: 10,975,247 ns/iter (+/- 22,692) test mediumxmltree ... bench: 11,601,320 ns/iter (+/- 46,216) test mediumelementtree ... bench: 11,550,227 ns/iter (+/- 17,991)
test tinyroxmltree ... bench: 7,697 ns/iter (+/- 41) test tinysdxdocument ... bench: 28,031 ns/iter (+/- 101) test tinyxmltree ... bench: 47,199 ns/iter (+/- 110) test tinytreexml ... bench: 50,399 ns/iter (+/- 55) test tinyelementtree ... bench: 51,569 ns/iter (+/- 165) ```
roxmltree uses [xmlparser] internally, while sdx-document uses its own implementation and xmltree, elementtree and treexml use the [xml-rs] crate. Here is a comparison between xmlparser and xml-rs:
```text test largexmlparser ... bench: 2,485,710 ns/iter (+/- 1,246) test largexmlrs ... bench: 28,252,304 ns/iter (+/- 27,852)
test mediumxmlparser ... bench: 624,192 ns/iter (+/- 1,040) test mediumxmlrs ... bench: 10,237,568 ns/iter (+/- 13,497)
test tinyxmlparser ... bench: 4,986 ns/iter (+/- 84) test tinyxmlrs ... bench: 45,832 ns/iter (+/- 50) ```
You can try it yourself by running cargo bench
in the benches
dir.
Notes:
xmlReadFile()
will parse only an XML structure,
without attributes normalization and stuff. So it's hard to compare.
And we have to use a separate benchmark utility.unsafe
code.This library uses Rust's idiomatic API based on iterators. In case you are more familiar with browser/JS DOM APIs - you can check out tests/dom-api.rs to see how it can be converted into a Rust one.
Rust >= 1.18
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.