pub struct XmlBuilder { /* private fields */ }Implementations§
Source§impl XmlBuilder
impl XmlBuilder
Sourcepub fn set_header(&mut self, header: &str)
pub fn set_header(&mut self, header: &str)
Overwrite the XML header (e.g., with a custom processing instruction)
Sourcepub fn clear_header(&mut self)
pub fn clear_header(&mut self)
Clear all XML headers
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic_usage.rs (line 17)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn set_schema(&mut self, txt_schema: &str)
pub fn set_schema(&mut self, txt_schema: &str)
Examples found in repository?
examples/basic_usage.rs (lines 20-34)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn set_key<K: ToString>(
&mut self,
nm_element: &str,
txt_key: K,
) -> ChainFromAdd<'_>
pub fn set_key<K: ToString>( &mut self, nm_element: &str, txt_key: K, ) -> ChainFromAdd<'_>
Examples found in repository?
examples/basic_usage.rs (line 44)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn clear_keys(&mut self)
pub fn clear_keys(&mut self)
Examples found in repository?
examples/basic_usage.rs (line 55)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn add_element<V: ToString>(
&mut self,
nm_element: &str,
value_element: V,
) -> ChainFromAdd<'_>
pub fn add_element<V: ToString>( &mut self, nm_element: &str, value_element: V, ) -> ChainFromAdd<'_>
Examples found in repository?
examples/basic_usage.rs (line 48)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn build_xml(&mut self)
pub fn build_xml(&mut self)
Examples found in repository?
examples/basic_usage.rs (line 67)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}Sourcepub fn xml_out(&self) -> &str
pub fn xml_out(&self) -> &str
Examples found in repository?
examples/basic_usage.rs (line 71)
3fn main() {
4
5
6 // example data
7 let employees = vec![
8 Employee { id: 1, first: "John", last: "Doe", dob: "1900-01-01" },
9 Employee { id: 2, first: "Jane", last: "Doe", dob: "1800-12-31" },
10 Employee { id: 3, first: "John", last: "Dough", dob: "1700-01-01" },
11
12 ];
13
14 // create an XmlBuilder struct
15
16 // this is an struct that allows you build an xml output in memory
17 let mut xb = XmlBuilder::new();
18
19 // define the schema you wish to populate in plain text
20 xb.set_schema("
21 <root>
22 <employee>
23 <name>
24 <first></first>
25 <last></last>
26 </name>
27 <info>
28 <dob></dob>
29 </info>
30 </employee>
31 <passing_str_ok></passing_str_ok>
32 <passing_i32_ok></passing_i32_ok>
33 <name!2></name!2>
34 </root>");
35
36 // default header is <?xml version="1.0" encoding="UTF-8"?>
37 // to add custom headers, multiple allowed use
38 // xb.set_header("your customer header, < > will be applied the the star/end automatically");
39
40 for e in employees{
41
42
43 // set element used to group to parent elements
44 xb.set_key("employee", e.id)
45 .attribute("id", e.id);
46
47 // unlike other libraries the parent elements are implicitly built
48 xb.add_element("first", e.first);
49 xb.add_element("last", e.last);
50
51 // you can chain into the cdata() method to enclose an element in cdata tags
52 xb.add_element("dob", e.dob).cdata();
53
54 // clears current key context
55 xb.clear_keys();
56 }
57
58
59 // values can be passed as ny type implementing to_string()
60 xb.add_element("passing_str_ok", "some str");
61 xb.add_element("passing_i32_ok", 111222333);
62
63 // duplicate element names should be distinguised by !AnyAlphaNumtext in the schema definition
64 xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
65
66 // builds the xml in the background
67 xb.build_xml();
68
69
70 // function .xml_out() returns string of the xml output
71 println!("{}", xb.xml_out());
72}pub fn attributes(&mut self, attributes: &[(&str, &str)])
Auto Trait Implementations§
impl Freeze for XmlBuilder
impl RefUnwindSafe for XmlBuilder
impl Send for XmlBuilder
impl Sync for XmlBuilder
impl Unpin for XmlBuilder
impl UnwindSafe for XmlBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more