pub struct Document { /* private fields */ }Expand description
A well-formed XML document with one root element.
Equality is semantic: two documents are equal when their declaration,
prolog, root, and epilog match. Retained source text and spans are
provenance and do not participate, so a document compares equal to itself
after Document::without_source.
Implementations§
Source§impl Document
impl Document
Sourcepub fn validate_schema(&self) -> SchemaReport
pub fn validate_schema(&self) -> SchemaReport
Validates this document against the ISO 23387 element grammar.
This is a stricter, structural check than Document::validate, which
reports advisory diagnostics. A conforming report means every checked
rule held: declared root, child sequence and cardinality, attribute
presence, and datatype facets.
Source§impl Document
impl Document
Sourcepub fn parse(xml: &str) -> Result<Self, ParseError>
pub fn parse(xml: &str) -> Result<Self, ParseError>
Parses with conservative production defaults.
Sourcepub fn parse_with_options(
xml: &str,
options: ParseOptions,
) -> Result<Self, ParseError>
pub fn parse_with_options( xml: &str, options: ParseOptions, ) -> Result<Self, ParseError>
Parses with explicit resource limits.
pub const fn declaration(&self) -> Option<&XmlDeclaration>
pub fn prolog(&self) -> &[Node]
pub const fn root(&self) -> &Element
pub fn epilog(&self) -> &[Node]
Sourcepub fn source(&self) -> Option<&str>
pub fn source(&self) -> Option<&str>
The exact text this document was parsed from, when it is still retained.
Sourcepub fn without_source(self) -> Self
pub fn without_source(self) -> Self
Drops the retained source text, keeping the semantic tree.
Useful when a caller wants to hold many documents in memory and does not
need byte-exact output. Afterwards Document::to_xml_string_exact
fails closed instead of reconstructing approximate bytes.
Sourcepub fn to_xml_string(&self) -> Result<String, WriteError>
pub fn to_xml_string(&self) -> Result<String, WriteError>
Serializes the semantic XML tree without dropping retained content.
Equivalent syntax may be normalized; use Document::to_xml_string_exact
when the output must match the parsed bytes.
Sourcepub fn to_xml_string_exact(&self) -> Result<String, ExactWriteError>
pub fn to_xml_string_exact(&self) -> Result<String, ExactWriteError>
Reproduces the parsed document byte-for-byte from retained source spans.
Every construct is emitted from the exact bytes the reader consumed, so attribute quoting, character-reference spelling, intra-tag whitespace, CDATA versus escaped text, and empty-element syntax all survive unchanged. The call fails rather than falling back to normalization when span provenance is missing.