1 stable release
1.0.0 | Apr 24, 2020 |
---|
#78 in #io-write
184 downloads per month
Used in 2 crates
10KB
119 lines
minidom_writer
Helper to write 'minidom::Element' into an XML. See documentation.
lib.rs
:
Helper for minidom
to write XML.
Description
The crate provides ElementWriter
which can write an Element
.
Example
use minidom::{Element, Node};
use minidom_writer::ElementWriter;
use std::io::Cursor;
let subtag = Element::builder("ns:subtag")
.attr("id", "my_subtag")
.append(Node::Text(String::from("Some text")))
.build();
let tag = Element::builder("tag")
.attr("id", "my_tag")
.append(subtag)
.build();
let write = Cursor::new(Vec::new());
let mut element_writer = ElementWriter::plain(write);
element_writer.write(&tag).unwrap();
let expected = r#"<?xml version="1.0" encoding="UTF-8"?><tag id="my_tag"><ns:subtag id="my_subtag">Some text</ns:subtag></tag>"#;
assert_eq!(expected, String::from_utf8(element_writer.into_inner().into_inner()).unwrap());
Dependencies
~1.5–2.1MB
~40K SLoC