pub struct Writer { /* private fields */ }Expand description
Write a document, specifying some formatting options
For example, the default is to use single-quotes for attributes. To use
double quotes for attributes, you need to use set_single_quotes(false).
use sxd_document::{Package, writer::Writer};
// Create a new document
let p = Package::new();
let doc = p.as_document();
let el = doc.create_element("hello");
el.set_attribute_value("a", "b");
doc.root().append_child(el);
// Format the document as bytes
let mut output = Vec::new();
Writer::new().set_single_quotes(false).format_document(&doc, &mut output);
// Check that the output is correct
let output_string = String::from_utf8(output).unwrap();
assert_eq!(output_string, r#"<?xml version="1.0"?><hello a="b"/>"#);Implementations§
Source§impl Writer
impl Writer
Sourcepub fn set_single_quotes(self, single_quotes: bool) -> Self
pub fn set_single_quotes(self, single_quotes: bool) -> Self
Set whether single quotes should be used for writing a document.
Sourcepub fn set_write_encoding(self, write_encoding: bool) -> Self
pub fn set_write_encoding(self, write_encoding: bool) -> Self
Set whether the encoding should be specified in the output document header.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Writer
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnwindSafe for Writer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more