Crate xml_creator
source ·Expand description
xml_creator
building a simple xml (with childs, attributes, CDATA…)
Usage
Use XMLElement to create elements with everything you need.
You can write an XML document by calling write on your root element.
Example
use std::fs::File;
use xml_creator::XMLElement;
let mut file = File::create("example.xml").unwrap();
let mut company = XMLElement::new("company");
company.add_attribute("name", "val");
let mut employee = XMLElement::new("employee");
// no escaping and CDATA needed
employee.add_text("Max Mustermann".to_string(), false, false);
let mut cdata = XMLElement::new("cdata");
// will get wrapped into CDATA
cdata.add_text("<p>Some Html</p>".to_string(), false, true);
company.add_child(cdata);
let mut escape = XMLElement::new("escape");
// < will get escaped
escape.add_text("<".to_string(), true, false);
company.add_child(escape);
// add employee to company
company.add_child(employee);
company.write(file).unwrap();
sample.xml
will contain:
<?xml version = "1.0" encoding = "UTF-8"?>
<company name="val">
<employee>Max Mustermann</employee>
<cdata><![CDATA[<p>Some Html</p>]]></cdata>
<escape><</escape>
</company>