minidom/
lib.rs

1// Copyright (c) 2020 lumi <lumi@pew.im>
2// Copyright (c) 2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
3// Copyright (c) 2020 Bastien Orivel <eijebong+minidom@bananium.fr>
4// Copyright (c) 2020 Astro <astro@spaceboyz.net>
5// Copyright (c) 2020 Maxime “pep” Buquet <pep@bouah.net>
6//
7// This Source Code Form is subject to the terms of the Mozilla Public
8// License, v. 2.0. If a copy of the MPL was not distributed with this
9// file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#![deny(missing_docs)]
12
13//! A minimal DOM crate built on top of quick-xml, targeting exclusively the subset of XML useful
14//! for XMPP.
15//!
16//! This library exports an `Element` struct which represents a DOM tree.
17//!
18//! # Example
19//!
20//! Run with `cargo run --example articles`. Located in `examples/articles.rs`.
21//!
22//! ```rust,ignore
23//! extern crate minidom;
24//!
25//! use minidom::Element;
26//!
27//! const DATA: &'static str = r#"<articles xmlns="article">
28//!     <article>
29//!         <title>10 Terrible Bugs You Would NEVER Believe Happened</title>
30//!         <body>
31//!             Rust fixed them all. &lt;3
32//!         </body>
33//!     </article>
34//!     <article>
35//!         <title>BREAKING NEWS: Physical Bug Jumps Out Of Programmer's Screen</title>
36//!         <body>
37//!             Just kidding!
38//!         </body>
39//!     </article>
40//! </articles>"#;
41//!
42//! const ARTICLE_NS: &'static str = "article";
43//!
44//! #[derive(Debug)]
45//! pub struct Article {
46//!     title: String,
47//!     body: String,
48//! }
49//!
50//! fn main() {
51//!     let root: Element = DATA.parse().unwrap();
52//!
53//!     let mut articles: Vec<Article> = Vec::new();
54//!
55//!     for child in root.children() {
56//!         if child.is("article", ARTICLE_NS) {
57//!             let title = child.get_child("title", ARTICLE_NS).unwrap().text();
58//!             let body = child.get_child("body", ARTICLE_NS).unwrap().text();
59//!             articles.push(Article {
60//!                 title: title,
61//!                 body: body.trim().to_owned(),
62//!             });
63//!         }
64//!     }
65//!
66//!     println!("{:?}", articles);
67//! }
68//! ```
69//!
70//! # Usage
71//!
72//! To use `minidom`, add this to your `Cargo.toml` under `dependencies`:
73//!
74//! ```toml,ignore
75//! minidom = "*"
76//! ```
77
78pub use quick_xml;
79
80pub mod convert;
81pub mod element;
82pub mod error;
83mod namespaces;
84pub mod node;
85mod prefixes;
86
87#[cfg(test)]
88mod tests;
89
90pub use convert::IntoAttributeValue;
91pub use element::{Children, ChildrenMut, Element, ElementBuilder};
92pub use error::{Error, Result};
93pub use namespaces::NSChoice;
94pub use node::Node;