use diet_xml::XmlBuilder;
fn main() {
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" },
];
let mut xb = XmlBuilder::new();
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>");
for e in employees{
xb.set_key("employee", e.id)
.attribute("id", e.id);
xb.add_element("first", e.first);
xb.add_element("last", e.last);
xb.add_element("dob", e.dob).cdata();
xb.clear_keys();
}
xb.add_element("passing_str_ok", "some str");
xb.add_element("passing_i32_ok", 111222333);
xb.add_element("name!2", "suffix !2 has been removed, this enables use of duplicate element names");
xb.build_xml();
println!("{}", xb.xml_out());
}
struct Employee {
id: usize,
first: &'static str,
last: &'static str,
dob: &'static str,
}