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

minidom

在rxml之上实现的一个小型简单的DOM,针对XMPP有用的XML子集

30个版本 (15个重大变更)

0.16.0 2024年7月23日
0.15.2 2023年5月13日
0.15.1 2023年1月15日
0.15.0 2022年7月13日
0.1.1 2017年2月25日

#164Web编程

Download history 20940/week @ 2024-05-03 24329/week @ 2024-05-10 28630/week @ 2024-05-17 22900/week @ 2024-05-24 28914/week @ 2024-05-31 25403/week @ 2024-06-07 25701/week @ 2024-06-14 22083/week @ 2024-06-21 18819/week @ 2024-06-28 20683/week @ 2024-07-05 22226/week @ 2024-07-12 25282/week @ 2024-07-19 25054/week @ 2024-07-26 30438/week @ 2024-08-02 23920/week @ 2024-08-09 23404/week @ 2024-08-16

107,611 每月下载量
用于 71 个Crates (46个直接使用)

MPL-2.0 许可证

74KB
1.5K SLoC

minidom

这是什么?

在rxml之上实现的一个最小化DOM库,专门针对XMPP有用的XML子集。


lib.rs:

在rxml之上构建的一个最小化DOMcrate,专门针对XMPP有用的XML子集。

此库导出一个Element结构,它表示一个DOM树。

示例

使用cargo run --example articles运行。位于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);
}

用法

要使用minidom,请将其添加到Cargo.toml中的dependencies

minidom = "*"

依赖项

~1MB
~23K SLoC