25 unstable releases

new 0.13.0 Jan 13, 2021
0.12.0 Feb 15, 2020
0.11.1 Sep 6, 2019
0.11.0 Jun 14, 2019
0.1.1 Feb 25, 2017

#28 in Parser implementations

Download history 1500/week @ 2020-09-27 1150/week @ 2020-10-04 1067/week @ 2020-10-11 926/week @ 2020-10-18 1010/week @ 2020-10-25 878/week @ 2020-11-01 1175/week @ 2020-11-08 1191/week @ 2020-11-15 727/week @ 2020-11-22 764/week @ 2020-11-29 922/week @ 2020-12-06 587/week @ 2020-12-13 484/week @ 2020-12-20 269/week @ 2020-12-27 1021/week @ 2021-01-03 1286/week @ 2021-01-10

3,609 downloads per month
Used in 23 crates (17 directly)

MPL-2.0 license

80KB
1.5K SLoC

minidom

What's this?

A minimal DOM library on top of quick-xml. targeting exclusively the subset of XML useful for XMPP.


lib.rs:

A minimal DOM crate built on top of quick-xml.

This library exports an Element struct which represents a DOM tree.

Example

Run with cargo run --example articles. Located in examples/articles.rs.

extern crate minidom;

use minidom::Element;

const DATA: &'static str = r#"<articles xmlns="article">
    <article>
        <title>10 Terrible Bugs You Would NEVER Believe Happened</title>
        <body>
            Rust fixed them all. &lt;3
        </body>
    </article>
    <article>
        <title>BREAKING NEWS: Physical Bug Jumps Out Of Programmer's Screen</title>
        <body>
            Just kidding!
        </body>
    </article>
</articles>"#;

const ARTICLE_NS: &'static str = "article";

#[derive(Debug)]
pub struct Article {
    title: String,
    body: String,
}

fn main() {
    let root: Element = DATA.parse().unwrap();

    let mut articles: Vec<Article> = Vec::new();

    for child in root.children() {
        if child.is("article", ARTICLE_NS) {
            let title = child.get_child("title", ARTICLE_NS).unwrap().text();
            let body = child.get_child("body", ARTICLE_NS).unwrap().text();
            articles.push(Article {
                title: title,
                body: body.trim().to_owned(),
            });
        }
    }

    println!("{:?}", articles);
}

Usage

To use minidom, add this to your Cargo.toml under dependencies:

minidom = "*"

Dependencies

~325KB