pub struct XmlDocument { /* private fields */ }Expand description
Reusable owned XML document.
The parsed view is retained across read-only operations. Every successful
mutation increments Self::generation and invalidates all identities
captured from previous views.
Implementations§
Source§impl XmlDocument
impl XmlDocument
Sourcepub fn parse(
xml: impl AsRef<str> + Into<String>,
) -> Result<Self, XmlDocumentError>
pub fn parse( xml: impl AsRef<str> + Into<String>, ) -> Result<Self, XmlDocumentError>
Parse and own an XML document using conservative XML input defaults. Borrowed input is size-checked before it is copied into owned storage.
Sourcepub fn parse_with_policy(
xml: impl AsRef<str> + Into<String>,
policy: &impl XmlDocumentPolicy,
) -> Result<Self, XmlDocumentError>
pub fn parse_with_policy( xml: impl AsRef<str> + Into<String>, policy: &impl XmlDocumentPolicy, ) -> Result<Self, XmlDocumentError>
Parse and own XML under the same immutable policy used by an operation. The policy’s byte ceiling is checked before borrowed input is copied.
Sourcepub const fn identity(&self) -> DocumentIdentity
pub const fn identity(&self) -> DocumentIdentity
Return this document’s stable provenance identity.
Sourcepub const fn generation(&self) -> u64
pub const fn generation(&self) -> u64
Return the current mutation generation.
Sourcepub fn as_xml(&self) -> &str
pub fn as_xml(&self) -> &str
Return the deterministic serialized representation of this generation.
Sourcepub fn into_xml(self) -> String
pub fn into_xml(self) -> String
Consume the document and return its deterministic serialization.
Sourcepub fn with_view<R>(
&self,
operation: impl for<'a> FnOnce(DocumentView<'a>) -> R,
) -> R
pub fn with_view<R>( &self, operation: impl for<'a> FnOnce(DocumentView<'a>) -> R, ) -> R
Borrow the retained parsed view without reparsing.
Sourcepub fn replace_element(
&mut self,
target: NodeIdentity,
replacement: &str,
) -> Result<(), XmlDocumentError>
pub fn replace_element( &mut self, target: NodeIdentity, replacement: &str, ) -> Result<(), XmlDocumentError>
Replace one complete element with a well-formed element fragment.
Sourcepub fn replace_node_with_fragment(
&mut self,
target: NodeIdentity,
replacement: &str,
) -> Result<(), XmlDocumentError>
pub fn replace_node_with_fragment( &mut self, target: NodeIdentity, replacement: &str, ) -> Result<(), XmlDocumentError>
Replace one complete node with an XML fragment valid in its parent context.
This operation is intended for XMLEnc Content replacement, where one
EncryptedData element can expand into multiple sibling nodes.
Sourcepub fn replace_content(
&mut self,
target: NodeIdentity,
replacement: &str,
) -> Result<(), XmlDocumentError>
pub fn replace_content( &mut self, target: NodeIdentity, replacement: &str, ) -> Result<(), XmlDocumentError>
Replace all children of one element with a well-formed XML fragment.
Sourcepub fn replace_contents(
&mut self,
replacements: &[(NodeIdentity, String)],
) -> Result<(), XmlDocumentError>
pub fn replace_contents( &mut self, replacements: &[(NodeIdentity, String)], ) -> Result<(), XmlDocumentError>
Replace the children of several non-overlapping elements atomically.
All identities must belong to the current generation. Every boundary is checked in one validation candidate, then the final candidate is parsed and either commits as one new generation or leaves the document unchanged.
Sourcepub fn append_child(
&mut self,
target: NodeIdentity,
child: &str,
) -> Result<(), XmlDocumentError>
pub fn append_child( &mut self, target: NodeIdentity, child: &str, ) -> Result<(), XmlDocumentError>
Append a well-formed XML fragment as the last child of an element.