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