#xml #xmpp #dom #top #element #targeting #subset

minidom

A small, simple DOM implementation on top of rxml, targeting the subset of XML useful for XMPP

29 unstable releases

0.15.2 May 13, 2023
0.15.1 Jan 15, 2023
0.15.0 Jul 13, 2022
0.14.0 Mar 7, 2022
0.1.1 Feb 25, 2017

#46 in Web programming

Download history 20111/week @ 2023-12-05 18706/week @ 2023-12-12 14183/week @ 2023-12-19 8321/week @ 2023-12-26 19604/week @ 2024-01-02 19204/week @ 2024-01-09 24679/week @ 2024-01-16 22418/week @ 2024-01-23 18890/week @ 2024-01-30 18292/week @ 2024-02-06 20534/week @ 2024-02-13 24647/week @ 2024-02-20 28759/week @ 2024-02-27 31190/week @ 2024-03-05 26451/week @ 2024-03-12 22799/week @ 2024-03-19

113,957 downloads per month
Used in 66 crates (42 directly)

MPL-2.0 license

72KB
1.5K SLoC

minidom

What's this?

A minimal DOM library on top of rxml, targeting exclusively the subset of XML useful for XMPP.


lib.rs:

A minimal DOM crate built on top of rxml, targeting exclusively the subset of XML useful for XMPP.

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

~665KB
~15K SLoC