Crate xmhell

source ·
Expand description

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(())
}

Re-exports

Structs

Enums

  • Library error types.

Traits

  • Methods for traversing an XML documented in structured fashion.