Struct glifparser::glif::xml::Element
source · pub struct Element {
pub prefix: Option<String>,
pub namespace: Option<String>,
pub namespaces: Option<Namespace>,
pub name: String,
pub attributes: IndexMap<String, String, RandomState>,
pub children: Vec<XMLNode, Global>,
}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: IndexMap<String, String, RandomState>The Element attributes
By default, this is a HashMap, but if the optional “attribute-order” feature is enabled,
this is an IndexMap, which will retain
item insertion order.
children: Vec<XMLNode, Global>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>(r: R) -> Result<Vec<XMLNode, Global>, ParseError>where
R: Read,
pub fn parse_all<R>(r: R) -> Result<Vec<XMLNode, Global>, ParseError>where
R: Read,
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
sourcepub fn parse<R>(r: R) -> Result<Element, ParseError>where
R: Read,
pub fn parse<R>(r: R) -> Result<Element, ParseError>where
R: Read,
Parses some data into an Element
sourcepub fn write<W>(&self, w: W) -> Result<(), EmitterError>where
W: Write,
pub fn write<W>(&self, w: W) -> Result<(), EmitterError>where
W: Write,
Writes out this element as the root element in an new XML document
sourcepub fn write_with_config<W>(
&self,
w: W,
config: EmitterConfig
) -> Result<(), EmitterError>where
W: Write,
pub fn write_with_config<W>(
&self,
w: W,
config: EmitterConfig
) -> Result<(), EmitterError>where
W: Write,
Writes out this element as the root element in a new XML document using the provided configuration
sourcepub fn get_child<P>(&self, k: P) -> Option<&Element>where
P: ElementPredicate,
pub fn get_child<P>(&self, k: P) -> Option<&Element>where
P: ElementPredicate,
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>(&mut self, k: P) -> Option<&mut Element>where
P: ElementPredicate,
pub fn get_mut_child<P>(&mut self, k: P) -> Option<&mut Element>where
P: ElementPredicate,
Find a child element with the given name and return a mutable reference to it.
sourcepub fn take_child<P>(&mut self, k: P) -> Option<Element>where
P: ElementPredicate,
pub fn take_child<P>(&mut self, k: P) -> Option<Element>where
P: ElementPredicate,
Find a child element with the given name, remove and return it.
Trait Implementations§
impl Eq for Element
impl StructuralEq for Element
impl StructuralPartialEq for Element
Auto Trait Implementations§
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.