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
impl Document
Sourcepub fn parse<'t>(
text: impl Into<Cow<'t, str>>,
base_uri: Option<&str>,
) -> Result<Rc<Self>, DocumentError>
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.
Sourcepub fn parse_loaded<'t>(
text: impl Into<Cow<'t, str>>,
uri: &str,
) -> Result<Rc<Self>, DocumentError>
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.
Sourcepub fn document_uri(&self) -> Option<&str>
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).
Sourcepub const fn has_xml_base(&self) -> bool
pub const fn has_xml_base(&self) -> bool
Whether some element has an xml:base attribute (whose effect on base URIs is not
implemented).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
The number of nodes, the document node and attributes included.