2017-03-08 19:34:17 +00:00
|
|
|
#![deny(missing_docs)]
|
|
|
|
|
2018-06-23 12:06:18 +00:00
|
|
|
//! A minimal DOM crate built on top of quick-xml.
|
2017-02-21 14:46:06 +00:00
|
|
|
//!
|
|
|
|
//! This library exports an `Element` struct which represents a DOM tree.
|
|
|
|
//!
|
|
|
|
//! # Example
|
|
|
|
//!
|
|
|
|
//! Run with `cargo run --example articles`. Located in `examples/articles.rs`.
|
|
|
|
//!
|
|
|
|
//! ```rust,ignore
|
|
|
|
//! 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);
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Usage
|
|
|
|
//!
|
2017-02-25 14:43:56 +00:00
|
|
|
//! To use `minidom`, add this to your `Cargo.toml` under `dependencies`:
|
2017-02-21 14:46:06 +00:00
|
|
|
//!
|
|
|
|
//! ```toml,ignore
|
2017-02-25 14:43:56 +00:00
|
|
|
//! minidom = "*"
|
2017-02-21 14:46:06 +00:00
|
|
|
//! ```
|
|
|
|
|
2017-06-07 20:40:53 +00:00
|
|
|
extern crate quick_xml;
|
2018-02-18 18:54:09 +00:00
|
|
|
extern crate failure;
|
|
|
|
#[macro_use] extern crate failure_derive;
|
2017-02-19 19:46:44 +00:00
|
|
|
|
2017-03-08 19:34:17 +00:00
|
|
|
pub mod error;
|
|
|
|
pub mod element;
|
|
|
|
pub mod convert;
|
2017-08-13 15:29:38 +00:00
|
|
|
mod namespace_set;
|
2017-02-19 19:46:44 +00:00
|
|
|
|
2017-03-08 19:34:17 +00:00
|
|
|
#[cfg(test)] mod tests;
|
2017-02-19 19:46:44 +00:00
|
|
|
|
2018-02-18 18:54:09 +00:00
|
|
|
pub use error::{Error, Result};
|
2017-03-08 19:34:17 +00:00
|
|
|
pub use element::{Element, Node, Children, ChildrenMut, ElementBuilder};
|
2018-12-23 14:40:23 +00:00
|
|
|
pub use convert::IntoAttributeValue;
|