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日 |
#164 在 Web编程
107,611 每月下载量
用于 71 个Crates (46个直接使用)
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. <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