1
0
mirror of https://gitlab.com/xmpp-rs/xmpp-rs.git synced 2024-07-03 11:50:35 +02:00
xmpp-rs/minidom/examples/articles.rs
Maxime “pep” Buquet 7064ef5c17 minidom/examples: silence warning on unused property in struct
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2023-06-01 16:25:38 +02:00

52 lines
1.3 KiB
Rust

// Copyright (c) 2020 lumi <lumi@pew.im>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
extern crate minidom;
use minidom::Element;
const DATA: &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: &str = "article";
#[derive(Debug)]
pub struct Article {
pub title: String,
pub 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);
}