pub struct XmlPrinter { /* private fields */ }Expand description
An XML serialization and streaming engine.
Implements XmlVisitor to serialize an in-memory Document, and provides
a stateful streaming API for manual XML generation without a DOM tree.
Implementations§
Source§impl XmlPrinter
impl XmlPrinter
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new pretty-printing printer.
The default indentation is 4 spaces.
Sourcepub fn new_compact() -> Self
pub fn new_compact() -> Self
Creates a new compact printer.
Compact mode outputs XML with zero indentation or newlines between elements.
Sourcepub fn compact() -> Self
pub fn compact() -> Self
Creates a new compact printer. Alias for Self::new_compact.
Sourcepub fn with_capacity(capacity: usize, compact: bool) -> Self
pub fn with_capacity(capacity: usize, compact: bool) -> Self
Creates a printer with a pre-allocated capacity.
Sourcepub fn set_bom(&mut self, use_bom: bool)
pub fn set_bom(&mut self, use_bom: bool)
Configures whether to emit the UTF-8 Byte Order Mark (BOM).
Sourcepub fn set_indent_str(&mut self, indent_str: &str)
pub fn set_indent_str(&mut self, indent_str: &str)
Configures the indentation string used in pretty-printed mode.
Sourcepub fn result(&self) -> &str
pub fn result(&self) -> &str
Returns the accumulated XML output as a string slice. Alias for Self::as_str.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the printer and returns the accumulated XML string.
Sourcepub fn push_header(
&mut self,
version: &str,
encoding: Option<&str>,
standalone: Option<bool>,
)
pub fn push_header( &mut self, version: &str, encoding: Option<&str>, standalone: Option<bool>, )
Writes the XML declaration: <?xml version="..." encoding="..." standalone="..."?>
Sourcepub fn open_element(&mut self, name: &str)
pub fn open_element(&mut self, name: &str)
Opens an XML element: <name (remains open for attributes).
Sourcepub fn push_attribute(&mut self, name: &str, value: &str)
pub fn push_attribute(&mut self, name: &str, value: &str)
Pushes an attribute key-value pair to the currently open element.
§Panics
Panics if no element is currently open for attributes.
Sourcepub fn close_element(&mut self)
pub fn close_element(&mut self)
Closes the currently open XML element: /> or </name>.
Sourcepub fn push_text_raw(&mut self, text: &str)
pub fn push_text_raw(&mut self, text: &str)
Pushes unescaped raw text content.
Sourcepub fn push_cdata(&mut self, text: &str)
pub fn push_cdata(&mut self, text: &str)
Pushes a CDATA section: <![CDATA[text]]>.
Sourcepub fn push_comment(&mut self, text: &str)
pub fn push_comment(&mut self, text: &str)
Pushes a comment: <!--text-->.
Sourcepub fn push_declaration(&mut self, text: &str)
pub fn push_declaration(&mut self, text: &str)
Pushes a declaration block: <?text?>.
Sourcepub fn push_unknown(&mut self, text: &str)
pub fn push_unknown(&mut self, text: &str)
Pushes an unknown block: <!text>.
Sourcepub fn push_declaration_node(&mut self, name: &str, attrs: &[Attribute])
pub fn push_declaration_node(&mut self, name: &str, attrs: &[Attribute])
Pushes a declaration node with attributes: <?name attr="value"?>.