Documentation

roxml

The XmlReader is designed to read XML in an efficient, zero-copy way without DOM structures or other intermediate representations. It has a lazy design, the navigation functions scan the source on demand. It is NOT an implementation of a XML processor. Its intent is to support traversing XML formatted data to directly create your own representation. It is aware of the basic XML structure: Prolog, Body (RootElement), Epilog, but does only basic input validation. It supports both std and no_std environments (requires alloc).

Usage

# extern crate roxml;
use roxml::prelude::*;

let xml = r#"<note priority="high">
    <to>Alice</to>
    <from>Bob</from>
    <body>Don't forget to feed the cat.</body>
</note>"#;

let reader = XmlReader::parse(xml);
let root = reader.root_element().expect("well-formed XML has a root");

assert_eq!(root.tag_name(), "note");
assert_eq!(root.attribute("priority"), Some("high"));

for child in root.children() {
    let BodyNode::Element(elem) = child else { continue };
    // Each child's text content is its first (Text) child node.
    let text = elem.first_child()
        .and_then(|n| if let BodyNode::Text(t) = n { Some(t.text()) } else { None })
        .unwrap_or("");
    match elem.tag_name() {
        "to"   => assert_eq!(text, "Alice"),
        "from" => assert_eq!(text, "Bob"),
        "body" => assert_eq!(text, "Don't forget to feed the cat."),
        _      => unreachable!(),
    }
}

License

Licensed under either of

at your option.

Contribution

Any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.