1 unstable release

0.1.0 Aug 11, 2023

#8 in #quick-xml

MIT license

15KB
175 lines

xmhell

A less hellscape-ish XML reader

This library extends quick-xml by adding methods to read deeply nested XML without endless nested loops of match statements.

See the documentation for details.


lib.rs:

A less hellscape-ish XML reader.

This library extends quick-xml by adding methods to read deeply nested XML without endless nested loops of match statements.

See Expect for details.

Example

use xmhell::{quick_xml::Reader, Error, Expect};

const IN: &str = r#"
    <root>
        <foo>
            <bar/>
            <bar/>
        </foo>
    </root>
"#;

fn main() -> Result<(), Error> {
    let mut bars = 0;

    let mut reader = Reader::from_str(IN);
    reader.trim_text(true);

    reader.expect_element("root")?.read_inner(|reader| {
        reader.expect_element("foo")?.read_inner(|reader| {
            while let Ok(()) = reader.expect_empty("bar") {
                bars += 1;
            }
            Ok(())
        })?;
        Ok(())
    })?;
    reader.expect_eof()?;

    assert_eq!(bars, 2);

    Ok(())
}

Dependencies

~1.5MB
~23K SLoC