Documentation

roxml::XmlReader

The XmlReader is designed to read xml in an efficient way without any DOM or other intermediate structures.

Usage

extern crate roxml;
use roxml::{XmlElementType, XmlReader};

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() {
    if child.element_type() != XmlElementType::Element {
        continue;
    }
    // Each child's text content is its first (Text) child node.
    let text = child.first_child().map(|n| n.text()).unwrap_or("");
    match child.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.