Skip to main content

Document

Struct Document 

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

An immutable XML tree.

The texts of its nodes live in one text space: the source text the document was parsed from, when the parser was given it as an owned String (offsets below its length), followed by the texts that are not written verbatim in it (offsets from its length on).

Implementations§

Source§

impl Document

Source

pub fn parse<'t>( text: impl Into<Cow<'t, str>>, base_uri: Option<&str>, ) -> Result<Rc<Self>, DocumentError>

Parses XML text. Every text node is kept, whitespace-only ones included; a document type declaration is refused (its default attributes and entities would change the tree without notice). base_uri, if given, is the base URI of every node (the location the text was read from, Saxon’s system id).

The text can be borrowed (&str) or given (String). Borrowed, the texts of the nodes are copied into the tree. Given, the tree keeps it and refers to it for every text written verbatim in it (text without entity or character references, line ends or, in attributes, whitespace to normalize): only the others are copied.

The document has no document URI: in Saxon-HE 12.10, fn:document-uri only knows the documents of its document pool, those that fn:document or fn:doc loaded, and is empty for a document given to the transformation, such as the one being validated. (Saxon 9.9 fell back to the system id.) A document loaded by fn:document is parsed with Document::parse_loaded.

§Errors

XML that is not well-formed or not namespace-well-formed, or that has a document type declaration.

Source

pub fn parse_loaded<'t>( text: impl Into<Cow<'t, str>>, uri: &str, ) -> Result<Rc<Self>, DocumentError>

Parses XML text as Document::parse does, for a document that fn:document loaded from uri (the absolute URI it resolved): uri is both its document URI and the base URI of its nodes, as for a document in Saxon’s document pool.

§Errors

Those of Document::parse.

Source

pub fn root(self: &Rc<Self>) -> Node

The document node.

Source

pub fn document_uri(&self) -> Option<&str>

The document URI (fn:document-uri), if any: only a document loaded by fn:document has one (see Document::parse).

Source

pub fn base_uri(&self) -> Option<&str>

The base URI of the document’s nodes, if any.

Source

pub const fn has_xml_base(&self) -> bool

Whether some element has an xml:base attribute (whose effect on base URIs is not implemented).

Source

pub fn node_count(&self) -> usize

The number of nodes, the document node and attributes included.

Trait Implementations§

Source§

impl Debug for Document

Source§

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

Formats the value using the given formatter. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.