November 2017
Beginner
308 pages
8h 32m
English
Writing an XML file is far more complex than reading. Here, we have to explicitly use XmlEvent and EventWriter. We also use EmitterConfig, which does as the name suggests, that is, creates a configuration and then uses it. EventWriter, EmitterConfig, and XmlEvent are all part of xml::writer.
Let us first consider the main function. First, create the file and two references, one to stdin and one to stdout, as follows:
let mut file = File::create("myxml_file.xml).unwrap();
let mut output = io::stdout();
let mut input = io::stdin();
Next, we create the writer via EmitterConfig:
let mut writer = EmitterConfig::new().preform_indent(true).create_writer(&mut file);
We now have the writer set up. perform_indent tells the writer to ...
Read now
Unlock full access