#xml-parser #xml #parse #parser

elementtree

Parse an XML file into Python elementtree like structure

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

#525 in Parser implementations

Download history 1385/week @ 2023-12-22 2005/week @ 2023-12-29 3506/week @ 2024-01-05 4572/week @ 2024-01-12 4812/week @ 2024-01-19 4691/week @ 2024-01-26 8718/week @ 2024-02-02 9594/week @ 2024-02-09 6309/week @ 2024-02-16 7646/week @ 2024-02-23 6577/week @ 2024-03-01 6010/week @ 2024-03-08 5391/week @ 2024-03-15 5470/week @ 2024-03-22 7072/week @ 2024-03-29 5627/week @ 2024-04-05

24,763 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–7MB
~14K SLoC