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.
14//!
15//! This library exports an `Element` struct which represents a DOM tree.
16//!
17//! # Example
18//!
19//! Run with `cargo run --example articles`. Located in `examples/articles.rs`.
20//!
21//! ```rust,ignore
22//! extern crate minidom;
23//!
24//! use minidom::Element;
25//!
26//! const DATA: &'static str = r#"<articles xmlns="article">
27//!     <article>
28//!         <title>10 Terrible Bugs You Would NEVER Believe Happened</title>
29//!         <body>
30//!             Rust fixed them all. &lt;3
31//!         </body>
32//!     </article>
33//!     <article>
34//!         <title>BREAKING NEWS: Physical Bug Jumps Out Of Programmer's Screen</title>
35//!         <body>
36//!             Just kidding!
37//!         </body>
38//!     </article>
39//! </articles>"#;
40//!
41//! const ARTICLE_NS: &'static str = "article";
42//!
43//! #[derive(Debug)]
44//! pub struct Article {
45//!     title: String,
46//!     body: String,
47//! }
48//!
49//! fn main() {
50//!     let root: Element = DATA.parse().unwrap();
51//!
52//!     let mut articles: Vec<Article> = Vec::new();
53//!
54//!     for child in root.children() {
55//!         if child.is("article", ARTICLE_NS) {
56//!             let title = child.get_child("title", ARTICLE_NS).unwrap().text();
57//!             let body = child.get_child("body", ARTICLE_NS).unwrap().text();
58//!             articles.push(Article {
59//!                 title: title,
60//!                 body: body.trim().to_owned(),
61//!             });
62//!         }
63//!     }
64//!
65//!     println!("{:?}", articles);
66//! }
67//! ```
68//!
69//! # Usage
70//!
71//! To use `minidom`, add this to your `Cargo.toml` under `dependencies`:
72//!
73//! ```toml,ignore
74//! minidom = "*"
75//! ```
76
77pub use quick_xml;
78
79pub mod convert;
80pub mod element;
81pub mod error;
82mod namespaces;
83pub mod node;
84mod prefixes;
85
86#[cfg(test)]
87mod tests;
88
89pub use convert::IntoAttributeValue;
90pub use element::{Children, ChildrenMut, Element, ElementBuilder};
91pub use error::{Error, Result};
92pub use namespaces::NSChoice;
93pub use node::Node;