#xml #dom #xmpp #rxml #top #element #subset

minidom

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

30 releases (15 breaking)

0.16.0 Jul 23, 2024
0.15.2 May 13, 2023
0.15.1 Jan 15, 2023
0.15.0 Jul 13, 2022
0.1.1 Feb 25, 2017

#338 in Web programming

Download history 22280/week @ 2024-08-26 23841/week @ 2024-09-02 23051/week @ 2024-09-09 23861/week @ 2024-09-16 25661/week @ 2024-09-23 22473/week @ 2024-09-30 25506/week @ 2024-10-07 25333/week @ 2024-10-14 28819/week @ 2024-10-21 27534/week @ 2024-10-28 26889/week @ 2024-11-04 22588/week @ 2024-11-11 22353/week @ 2024-11-18 18566/week @ 2024-11-25 19379/week @ 2024-12-02 22064/week @ 2024-12-09

83,150 downloads per month
Used in 73 crates (47 directly)

MPL-2.0 license

74KB
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

~1MB
~23K SLoC