pub struct Element { /* private fields */ }Expand description
An XML element retaining names, namespace resolution, attributes, and order.
Equality compares semantic identity and content only. Source spans are provenance for the exact writer, so two elements parsed from differently spelled but equivalent syntax remain equal.
Implementations§
Source§impl Element
impl Element
Sourcepub fn new(
namespace: Option<&str>,
prefix: Option<&str>,
local_name: &str,
) -> Self
pub fn new( namespace: Option<&str>, prefix: Option<&str>, local_name: &str, ) -> Self
Builds a fresh element with no retained source provenance.
namespace is the element’s resolved namespace URI, independent of
prefix. Elements built this way carry no spans, so
Document::to_xml_string works on them but
Document::to_xml_string_exact fails closed with
ExactWriteError::NoSource — there is no retained source to slice.
This constructor does not emit an xmlns declaration for namespace;
use Document::standalone to wrap a built root with the xmlns:dt
binding codecs need.
Sourcepub fn with_attribute(self, attribute: Attribute) -> Self
pub fn with_attribute(self, attribute: Attribute) -> Self
Appends an attribute, returning self for chained construction.
Sourcepub fn with_child(self, child: Element) -> Self
pub fn with_child(self, child: Element) -> Self
Appends a child element as a node, returning self for chained
construction.
Sourcepub fn with_text(self, text: impl Into<String>) -> Self
pub fn with_text(self, text: impl Into<String>) -> Self
Appends a text node, returning self for chained construction.
pub fn qname(&self) -> &str
pub fn prefix(&self) -> Option<&str>
pub fn local_name(&self) -> &str
pub fn namespace_uri(&self) -> Option<&str>
pub fn attributes(&self) -> &[Attribute]
pub fn nodes(&self) -> &[Node]
Sourcepub const fn was_empty_element(&self) -> bool
pub const fn was_empty_element(&self) -> bool
Whether the source used an empty-element tag such as <dt:Property/>.
Sourcepub fn children(&self) -> impl Iterator<Item = &Element>
pub fn children(&self) -> impl Iterator<Item = &Element>
Direct child elements in document order.
Sourcepub fn attribute_ns(
&self,
namespace_uri: Option<&str>,
local_name: &str,
) -> Option<&str>
pub fn attribute_ns( &self, namespace_uri: Option<&str>, local_name: &str, ) -> Option<&str>
Finds an attribute by resolved namespace URI and local name.
Sourcepub fn direct_text(&self) -> String
pub fn direct_text(&self) -> String
Direct semantic text and CDATA content, preserving order.