pub struct XmlStreamWriter<W: Write> { /* private fields */ }Expand description
Direct XML event writer with bounded output and namespace/state validation.
Implementations§
Source§impl<W: Write> XmlStreamWriter<W>
impl<W: Write> XmlStreamWriter<W>
Sourcepub fn new(inner: W) -> Result<Self, Error>
pub fn new(inner: W) -> Result<Self, Error>
Creates a writer with default bounded output options.
§Errors
Returns an error if initial writer setup or declaration output fails.
Sourcepub fn with_options(inner: W, options: XmlWriteOptions) -> Result<Self, Error>
pub fn with_options(inner: W, options: XmlWriteOptions) -> Result<Self, Error>
Creates a writer with explicit output options.
§Errors
Returns an error when any option limit is zero or the optional XML declaration cannot be written within the configured output bound.
Sourcepub fn start_element<'a, I, A>(
&mut self,
name: &str,
attributes: I,
) -> Result<(), Error>
pub fn start_element<'a, I, A>( &mut self, name: &str, attributes: I, ) -> Result<(), Error>
Starts a non-empty element with attributes.
§Errors
Returns an error for invalid names, attributes, namespace bindings, document state, depth or attribute limits, output overflow, or sink I/O failure.
Sourcepub fn empty_element<'a, I, A>(
&mut self,
name: &str,
attributes: I,
) -> Result<(), Error>
pub fn empty_element<'a, I, A>( &mut self, name: &str, attributes: I, ) -> Result<(), Error>
Writes an empty element with attributes.
§Errors
Returns an error for invalid names, attributes, namespace bindings, document state, depth or attribute limits, output overflow, or sink I/O failure.
Sourcepub fn start(&mut self, name: &str) -> Result<(), Error>
pub fn start(&mut self, name: &str) -> Result<(), Error>
Starts a non-empty element without attributes.
§Errors
Returns any validation, state, safety-limit, or I/O error from Self::start_element.
Sourcepub fn empty(&mut self, name: &str) -> Result<(), Error>
pub fn empty(&mut self, name: &str) -> Result<(), Error>
Writes an empty element without attributes.
§Errors
Returns any validation, state, safety-limit, or I/O error from Self::empty_element.
Sourcepub fn end_element(&mut self) -> Result<(), Error>
pub fn end_element(&mut self) -> Result<(), Error>
Ends the innermost open element.
§Errors
Returns an error when no element is open, the output bound is exceeded, or the sink fails.
Sourcepub fn text(&mut self, value: &str) -> Result<(), Error>
pub fn text(&mut self, value: &str) -> Result<(), Error>
Writes escaped XML character data.
§Errors
Returns an error for invalid XML characters, non-whitespace text outside the root, output overflow, or sink I/O failure.
Sourcepub fn cdata(&mut self, value: &str) -> Result<(), Error>
pub fn cdata(&mut self, value: &str) -> Result<(), Error>
Writes one CDATA section.
§Errors
Returns an error for invalid XML characters, CDATA outside the root, a ]]> terminator in
the value, output overflow, or sink I/O failure.
Sourcepub fn comment(&mut self, value: &str) -> Result<(), Error>
pub fn comment(&mut self, value: &str) -> Result<(), Error>
Writes one XML comment.
§Errors
Returns an error for invalid XML characters or hyphen sequences, output overflow, or sink I/O failure.
Sourcepub fn processing_instruction(
&mut self,
target: &str,
content: Option<&str>,
) -> Result<(), Error>
pub fn processing_instruction( &mut self, target: &str, content: Option<&str>, ) -> Result<(), Error>
Writes one processing instruction.
§Errors
Returns an error for an invalid or reserved target, invalid content characters or ?>
sequence, output overflow, or sink I/O failure.
Sourcepub fn validated_subtree(&mut self, subtree: &ValidatedXml) -> Result<(), Error>
pub fn validated_subtree(&mut self, subtree: &ValidatedXml) -> Result<(), Error>
Embeds one already validated, self-contained XML root below the current element.
§Errors
Returns an error when no parent element is open, the subtree would inherit an incompatible default namespace, exceeds writer depth or attribute limits, exceeds the output bound, or the sink fails.
pub fn written_bytes(&self) -> usize
pub fn get_ref(&self) -> &W
Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Returns a mutable reference to the output sink without ending the XML document.
This is intended for sinks that expose already-written bounded chunks while the writer retains ownership of XML namespace and document state. Mutating the sink must not change or discard bytes that it has previously reported as successfully written.