52 releases (26 breaking)

0.28.0 Nov 18, 2024
0.27.0 Oct 31, 2024
0.24.0 Apr 19, 2024
0.23.0 Mar 22, 2024
0.7.1 Dec 22, 2022

#821 in Data structures

Download history 106/week @ 2024-09-11 32/week @ 2024-09-18 45/week @ 2024-09-25 6/week @ 2024-10-02 8/week @ 2024-10-09 104/week @ 2024-10-23 289/week @ 2024-10-30 44/week @ 2024-11-06 125/week @ 2024-11-13 53/week @ 2024-11-20 6/week @ 2024-11-27

251 downloads per month
Used in natural-xml-diff

MIT license

405KB
7.5K SLoC

Xot - XML Object Tree

Crates.io Documentation

Xot is a full-featured XML tree access and manipulation library for Rust. With Xot you can load XML data into an object tree which you can then manipulate, and serialize back out to XML.

API Documentation

Features

  • Extensive XML tree access and manipulation API.

  • You can access the parent of a node! A lot of Rust XML tree libraries do not support this features: xmltree-rs, RustyXML, minidom and elementtree all lack this ability for instance. roxmltree does allow parent access, but is read-only.

  • Move nodes out of trees, into trees, into other trees with ease.

  • Access to the entire XML structure, including comments and processing instructions, and support for namespace and attribute nodes.

  • Compact storage of XML data, with efficient traversal.

  • Parse XML into a tree, and serialize back to XML.

  • Pretty-printing. Removal of non-significant whitespace.

Support

Xot has well-rounded XML support. Supported are namespaces for both elements and attributes. You can also get comments and processing instructions.

Xot exposes the entire XML structure for access and programmatic manipulation.

Limitations

There are the following limitations:

  • DTDs are not supported.
  • Only XML 1.0 is supported.

Why another XML library for Rust?

Use Xot if you need to be able to access XML as a tree, mutate it where necessary, and serialize it back out again. Various Rust XML tree libraries exist but none seem particularly interested in a complete tree manipulation API, including parent access, so Xot aims to fill that gap.

If you need to access XML as a tree, very high performance, and do not need tree manipulation or serialization at all, I recommend roxmltree.

For extensive features such as Xpath as well as tree manipulation, you can use libxml which wraps the libxml2 C library. Unfortunately its tree access facilities aren't entirely complete, and I've experienced odd errors and even crashes when using it; this was part of the reason I created Xot.

If you need to process big XML data with high performance, you may not want to use a tree library and instead use one of the various XML parser/serialization libraries.

Implementation notes

Xot underneath uses the indextree crate. Xot completely wraps the indextree functionality but the various operations it allows are taken from indextree.

Dependencies

~4–6.5MB
~168K SLoC