Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

A Document represents a DOM plus additional (optional) metadata such as one or more Document Type Declarations (DTD). Use this struct to write a DOM to a string or file.

Implementations§

Source§

impl Document

Source

pub fn new(root: Element) -> Self

Constructs a new Document with the given root element and default declaration

Source

pub fn new_with_decl_dtd( root: Element, declaration: Option<Declaration>, dtd: Option<&[DTD]>, ) -> Self

Full constructor with required root element and optional XML declaration and optional list of one or more document type definition (DTD) items.

Source

pub fn doctype_defs(&self) -> impl Iterator<Item = &DTD>

Returns a list of any and all DTDs for this Document as an iterator

Source

pub fn doctype_defs_mut(&mut self) -> impl Iterator<Item = &mut DTD>

Returns a list of any and all DTDs for this Document as an iterator

Source

pub fn set_doctype_defs(&mut self, dtds: Option<&[DTD]>)

Sets the DTDs for this document (a None argument will remove all DTDs)

Source

pub fn declaration(&self) -> &Option<Declaration>

Gets the XML declaration for this document, if it has one (while the XML spec requires a declaration at the start of every XML file, it is commonly omitted, especially when the XML is embedded in a stream or file).

Source

pub fn set_declaration(&mut self, decl: Option<Declaration>)

Sets the XML declaration for this document (a None argument will remove any existing declaration). While the XML spec requires a declaration at the start of every XML file, it is commonly omitted, especially when the XML is embedded in a stream or file.

Source

pub fn to_string(&self) -> String

Produces the XML text representing this XML DOM using the default indent of two spaces per level

Source

pub fn to_string_with_indent(&self, indent: impl Into<String>) -> String

Produces the XML text representing this XML DOM using the provided indent.

§Args:
  • indent - prefix string to use for indenting the output XML. The indent must be either a single tab character or any number of spaces (otherwise a warning will be printed and the default indent used instead)
Source

pub fn write_to_filepath(&self, path: impl AsRef<Path>) -> Result<()>

Writes this document as XML to the given file using the default indent of two spaces per level, returning a result indicating success or error in this write operation

Source

pub fn write_to_filepath_with_indent( &self, path: impl AsRef<Path>, indent: impl Into<String>, ) -> Result<()>

Writes this document as XML to the given file using the provided indent, returning a result indicating success or error in this write operation

Source

pub fn write_to_file(&self, out: &mut impl Write) -> Result<()>

Writes this document as XML to the given file or stream using the default indent of two spaces per level, returning a result indicating success or error in this write operation

Source

pub fn write_to_file_with_indent( &self, out: &mut impl Write, indent: impl Into<String>, ) -> Result<()>

Writes this document as XML to the given file or stream using the default indent of two spaces per level, returning a result indicating success or error in this write operation

Source

pub fn root_element(&self) -> &Element

Returns the root element of this DOM as an immutable reference

Source

pub fn root_element_mut(&mut self) -> &mut Element

Returns the root element of this DOM as a mutable reference.

Trait Implementations§

Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.