#xml #dom #fork #element #quick-xml #top #minidom

domino

A small, simple DOM implementation on top of quick-xml. Fork of minidom not targetted at XMPP only

1 unstable release

0.0.1 Jan 15, 2022

#5 in #minidom

MPL-2.0 license

79KB
1.5K SLoC

domino

What's this?

This is a fork of minidom (https://crates.io/crates/minidom) that isn't targetted at XMPP only.

Differences

Right now the main difference is the fact that domino doesn't require elements to be in a namespace.


lib.rs:

A minimal DOM crate built on top of quick-xml, 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 domino;

use domino::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 domino, add this to your Cargo.toml under dependencies:

domino = "0.0.1"

Dependencies

~1.5MB
~21K SLoC