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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! # diet-xml
//!
//! A schema-driven, ergonomic XML builder for Rust.
//!
//! ## Example
//! ```rust
//! use diet_xml::XmlBuilder;
//!
//! fn main() {
//!
//! // example data
//! let employees = vec![
//! Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
//! Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
//! Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
//! ];
//!
//! // create an XmlBuilder struct
//!
//! // this is a struct that allows you build an xml output in memory
//! let mut xb = XmlBuilder::new();
//!
//! // define the schema you wish to populate in plain text
//! xb.set_schema("
//! <root>
//! <employee>
//! <name>
//! <first></first>
//! <last></last>
//! </name>
//! <info>
//! <dob></dob>
//! </info>
//! </employee>
//! <passing_str_ok></passing_str_ok>
//! <passing_i32_ok></passing_i32_ok>
//! <name!2></name!2>
//! </root>");
//!
//! // default header is <?xml version="1.0" encoding="UTF-8"?>
//! // to remove all headers use xb.clear_header();
//! // to set customer header use xb.set_header("your customer header, < > will be applied the the star/end automatically");
//!
//! for e in employees{
//!
//! // we want each id to relate to it's own employee element
//! // so use the id as the key
//! // we can also chain into attributes to have the id display as an element attribute
//!
//! // these arguments can be anything that implments .to_string()
//! // eg String, usize, &str, int
//! // (element_the_key_is_on, key_value)
//! // this is to allow the other to quickly add values to elements
//! // without needing boiler plate to convert to text where possible
//!
//! xb.set_key("employee", e.id)
//! .attribute("id", e.id);
//!
//! // you can chain either an add_element or set_key into .attribute
//! // this takes two arguments
//! // these arguments can be anything that implments .to_string()
//! // eg String, usize, &str, int
//! // (attribute_name, attribute_value)
//! // the .attributes() method can be used to add multiple attributes
//! // this should be passed in the form
//! // &[(&str,&str),(&str,&str),(&str,&str),(&str,&str)]
//! // tuples pairs of &str with attribute name and value
//! // attribute and attributes can be chained from add_element also
//!
//! // now we simply add the element values we want populated
//! // there is no need to build the entire structure
//! // unlike other libraries the parent elements are implicitly built
//! xb.add_element("first", e.first);
//! xb.add_element("last", e.last);
//!
//! // you can chain into the cdata() method to enclose an element in cdata tags
//! xb.add_element("dob", e.dob).cdata();
//!
//! // clears keys resets all context to a default value
//! // this isn't necessary in this sample program
//! // as keys are all overwritten on each iteration
//! // keys retain their state until either overwritten or cleared
//! xb.clear_keys();
//! }
//!
//!
//! // passing any type that implements to_string as a value for
//! // add_element, attribute(), set_key is ok
//! xb.add_element("passing_str_ok", "some str");
//! xb.add_element("passing_i32_ok", 111222333);
//!
//! // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
//! // the suffix will be remove when the XML is produced
//! xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
//!
//! // builds the xml in the background
//! xb.build_xml();
//!
//!
//! // function .xml_out() returns string of the xml output
//! println!("{}", xb.xml_out());
//! }
//!
//! struct Employee {
//! id: usize,
//! first: &'static str,
//! last: &'static str,
//! dob: &'static str,
//! }
//! ```
// Public facing API
// Re-export ChainFromAdd so users can call .attributes()
pub use ChainFromAdd;