[][src]Struct sxd_document::writer::Writer

pub struct Writer { /* fields omitted */ }

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"/>"#);

Methods

impl Writer[src]

pub fn new() -> Self[src]

Create a new Writer with default settings.

pub fn set_single_quotes(self, single_quotes: bool) -> Self[src]

Set whether single quotes should be used for writing a document.

impl Writer[src]

pub fn format_document<'d, W: ?Sized>(
    &self,
    doc: &'d Document<'d>,
    writer: &mut W
) -> Result<()> where
    W: Write
[src]

Formats a document into a Write

Trait Implementations

impl Default for Writer[src]

Auto Trait Implementations

impl Send for Writer

impl Sync for Writer

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]