pub struct Element {
pub prefix: Option<String>,
pub namespace: Option<String>,
pub namespaces: Option<Namespace>,
pub name: String,
pub attributes: AttributeMap<String, String>,
pub children: Vec<XMLNode>,
}Expand description
Represents an XML element.
Fields§
§prefix: Option<String>This elements prefix, if any
namespace: Option<String>This elements namespace, if any
namespaces: Option<Namespace>The full list of namespaces, if any
The Namespace type is exported from the xml-rs crate.
name: StringThe name of the Element. Does not include any namespace info
attributes: AttributeMap<String, String>The Element attributes
By default, this is a HashMap, but there are two optional features that can change this:
- If the “attribute-order” feature is enabled, then this is an IndexMap, which will retain item insertion order.
- If the “attribute-sorted” feature is enabled, then this is a
std::collections::BTreeMap, which maintains keys in sorted order.
children: Vec<XMLNode>Children
Implementations§
Source§impl Element
impl Element
Sourcepub fn new(name: &str) -> Element
pub fn new(name: &str) -> Element
Create a new empty element with given name
All other fields are empty
Sourcepub fn parse_all<R: Read>(r: R) -> Result<Vec<XMLNode>, ParseError>
pub fn parse_all<R: Read>(r: R) -> Result<Vec<XMLNode>, ParseError>
Parses some data into a list of XMLNodes
This is useful when you want to capture comments or processing instructions that appear before or after the root node
pub fn parse_all_with_config<R: Read>( r: R, parser_config: ParserConfig, ) -> Result<Vec<XMLNode>, ParseError>
pub fn parse_with_config<R: Read>( r: R, config: ParserConfig, ) -> Result<Element, ParseError>
Sourcepub fn write<W: Write>(&self, w: W) -> Result<(), Error>
pub fn write<W: Write>(&self, w: W) -> Result<(), Error>
Writes out this element as the root element in an new XML document
Sourcepub fn write_with_config<W: Write>(
&self,
w: W,
config: EmitterConfig,
) -> Result<(), Error>
pub fn write_with_config<W: Write>( &self, w: W, config: EmitterConfig, ) -> Result<(), Error>
Writes out this element as the root element in a new XML document using the provided configuration
Sourcepub fn get_child<P: ElementPredicate>(&self, k: P) -> Option<&Element>
pub fn get_child<P: ElementPredicate>(&self, k: P) -> Option<&Element>
Find a child element with the given name and return a reference to it.
Both &str and String implement ElementPredicate and can be used to search for child
elements that match the given element name with .get_child("element_name"). You can also
search by ("element_name", "tag_name") tuple.
Note: this will only return Elements. To get other nodes (like comments), iterate through
the children field.
Sourcepub fn get_mut_child<P: ElementPredicate>(
&mut self,
k: P,
) -> Option<&mut Element>
pub fn get_mut_child<P: ElementPredicate>( &mut self, k: P, ) -> Option<&mut Element>
Find a child element with the given name and return a mutable reference to it.
Sourcepub fn take_child<P: ElementPredicate>(&mut self, k: P) -> Option<Element>
pub fn take_child<P: ElementPredicate>(&mut self, k: P) -> Option<Element>
Find a child element with the given name, remove and return it.
Sourcepub fn get_text<'a>(&'a self) -> Option<Cow<'a, str>>
pub fn get_text<'a>(&'a self) -> Option<Cow<'a, str>>
Returns the inner text/cdata of this element, if any.
If there are multiple text/cdata nodes, they will be all concatenated into one string.
Sourcepub fn matches<P: ElementPredicate>(&self, k: P) -> bool
pub fn matches<P: ElementPredicate>(&self, k: P) -> bool
Checks if this element matches the predicate.