xml-creator
A Rust library for building a simple xml (with childs, attributes, CDATA...)
Documentation
Usage
Add this to your Cargo.toml
:
[dependencies]
xml-creator = "0.0.1"
and/or this to your crate root:
extern crate xml_creator;
Example
use std::io;
fn main() -> io::Result<()> {
use std::fs::File;
use xml_creator::XMLElement;
let mut file: Vec<u8> = Vec::new();
let mut company = XMLElement::new("company");
company.add_attribute("name", "val");
let mut employee = XMLElement::new("employee");
employee.add_text("Max Mustermann".to_string(), false, false);
let mut cdata = XMLElement::new("cdata");
cdata.add_text("<p>Some Html</p>".to_string(), false, true);
company.add_child(cdata);
let mut escape = XMLElement::new("escape");
escape.add_text("<".to_string(), true, false);
company.add_child(escape);
company.add_child(employee);
company.write(file)..unwrap();
Ok(())
}
example.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>