13 releases (5 stable)

1.2.3 Jan 4, 2023
1.2.2 Sep 2, 2022
1.2.1 Aug 22, 2022
0.7.0 Jan 15, 2022
0.2.0 Mar 30, 2017

#792 in Parser implementations

Download history 6308/week @ 2024-06-13 5020/week @ 2024-06-20 5408/week @ 2024-06-27 6300/week @ 2024-07-04 6112/week @ 2024-07-11 6606/week @ 2024-07-18 8046/week @ 2024-07-25 6542/week @ 2024-08-01 7327/week @ 2024-08-08 5692/week @ 2024-08-15 5123/week @ 2024-08-22 5542/week @ 2024-08-29 7375/week @ 2024-09-05 4978/week @ 2024-09-12 5916/week @ 2024-09-19 7145/week @ 2024-09-26

26,707 downloads per month
Used in 26 crates (8 directly)

MIT license

235KB
5.5K SLoC

ElementTree for Rust

Build Status Crates.io License rustc 1.56.0 Documentation

This library parses XML into a Python ElementTree like structure. It currently has basic support for reading and writing with pretty good namespace support and the ability to inspect the file.

It's not recommended to use this for larger documents as the entire document will be loaded into memory. However it's pretty good for working with configuration files and similar things.

Example

let root = Element::from_reader(r#"<?xml version="1.0"?>
<root xmlns="tag:myns" xmlns:foo="tag:otherns">
    <list a="1" b="2" c="3">
        <item foo:attr="foo1"/>
        <item foo:attr="foo2"/>
        <item foo:attr="foo3"/>
    </list>
</root>
"#.as_bytes()).unwrap();
let list = root.find("{tag:myns}list").unwrap();
for child in list.find_all("{tag:myns}item") {
    println!("attribute: {}", child.get_attr("{tag:otherns}attr").unwrap());
}

Dependencies

~0.5–5MB
~14K SLoC