1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! A tree-like parser to read, modify and write XML files.
//!
//! It was especially designed for modifying xml files without rigid structure.
//!
//! Parsing from various encodings are supported, including UTF-16, ISO 8859-1, GBK and EUC-KR. (With the notable exception of UTF-32)
//!
//! The XML document is represented with [`Document`], [`Element`] and [`Node`].
//!
//!
//! # Example
//! ```
//! use xml_doc::{Document, Element, Node};
//!
//! const data: &'static str = r#"<?xml version="1.0" encoding="utf-8"?>
//! <metadata>
//! <title>The Felloship of the Ring</title>
//! <author>J. R. R. Tolkien</author>
//! <date>1954</date>
//! </metadata>
//! "#;
//!
//! let mut doc = Document::parse_str(data).unwrap();
//! let metadata = doc.root_element().unwrap();
//!
//! // Add a new element
//! let series = Element::build(&mut doc, "series")
//! .text_content("Lord of the Rings")
//! .push_to(metadata);
//!
//! // Modify existing element
//! let date = metadata.find(&doc, "date").unwrap();
//! date.set_text_content(&mut doc, "29 July 1954");
//!
//! let xml = doc.write_str();
//! ```
//!
//! Below example goes through the root element's children and removes all nodes that isn't `<conf>...</conf>`
//! ```no_run
//! use std::path::Path;
//! use xml_doc::{Document, Node};
//!
//! let xml_file = Path::new("config.xml");
//! let mut doc = Document::parse_file(&xml_file).unwrap();
//! let root = doc.root_element().unwrap();
//! let to_remove: Vec<usize> = root.children(&doc)
//! .iter()
//! .enumerate()
//! .filter_map(|(i, node)| {
//! if let Node::Element(elem) = node {
//! if elem.name(&doc) == "conf" {
//! return None
//! }
//! }
//! Some(i)
//! })
//! .collect();
//! for i in to_remove.iter().rev() {
//! root.remove_child(&mut doc, *i);
//! }
//! doc.write_file(&xml_file);
//! ```
//!
pub use crate;
pub use crate;
pub use crate;
pub use crate;