Crate minidom

source ·
Expand description

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.


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

extern crate minidom;

use minidom::Element;

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

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

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"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);


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

minidom = "*"



  • A module which exports a few traits for converting types to elements and attributes.
  • Provides an Element type, which represents DOM nodes, and a builder to create them with.
  • Provides an error type for this crate.
  • Provides the Node struct, which represents a node in the DOM.
  • SAX events to DOM tree conversion