pub struct Element { /* private fields */ }Expand description
Represents an Element in an XML Document.
Implementations§
Source§impl Element
impl Element
Sourcepub fn children(&self) -> impl Iterator<Item = &Element>
pub fn children(&self) -> impl Iterator<Item = &Element>
Returns the ‘child’ elements of the current element. Consider the XML document:
<r>
<a/>
<b/>
</r>r’s children() function would return an iterator over ‘a’ and ‘b’.
Text nodes, processing instructions and comments are skipped/ignored by the iterator.
Sourcepub fn children_mut(&mut self) -> impl Iterator<Item = &mut Element>
pub fn children_mut(&mut self) -> impl Iterator<Item = &mut Element>
Returns the ‘child’ elements of the current element. Consider the XML document:
<r>
<a/>
<b/>
</r>r’s children_mut() function would return an iterator over ‘a’ and ‘b’.
Text nodes, processing instructions and comments are skipped/ignored by the iterator.
Sourcepub fn child<S: AsRef<str>>(&self, name: S) -> Option<&Element>
pub fn child<S: AsRef<str>>(&self, name: S) -> Option<&Element>
Find the first occurrance specific child element (does not recurse to lower levels of children).
Sourcepub fn add_cdata<S: Into<String>>(&mut self, cdata: S) -> Result<(), XDocErr>
pub fn add_cdata<S: Into<String>>(&mut self, cdata: S) -> Result<(), XDocErr>
Add a CDATA node. Will error if the string contains ]]> as this cannot be represented in
a CDATA node.
Sourcepub fn nodes_len(&self) -> usize
pub fn nodes_len(&self) -> usize
Get the number of nodes (of any kind) that are children of this node.
Sourcepub fn first_node(&self) -> Option<&Node>
pub fn first_node(&self) -> Option<&Node>
Get the first child node (of any kind)
Sourcepub fn fullname(&self) -> &str
pub fn fullname(&self) -> &str
The fullname of the element (including both the namespace alias prefix and the name). For
example, if the name of this element is ns:foo, this function returns "ns:foo".
Element::name and [Element:prefix] give the parsed sections of the fullname.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The name of the element without its prefix. For example, if the name of this element is
ns:foo, name() will return foo.
Sourcepub fn prefix(&self) -> Option<&str>
pub fn prefix(&self) -> Option<&str>
The name of the element’s namespace alias prefix. For example, if the name of this element
is ns:foo, prefix() will return Some("ns").
Sourcepub fn set_name<S: AsRef<str>>(&mut self, name: S)
pub fn set_name<S: AsRef<str>>(&mut self, name: S)
Sets the name of this element without changing the namespace alias prefix. For example, if
the name of this element is ns:foo then set_name("bar") will change the fullname to
ns:bar.
Sourcepub fn set_prefix<S: AsRef<str>>(&mut self, prefix: S) -> Result<(), XDocErr>
pub fn set_prefix<S: AsRef<str>>(&mut self, prefix: S) -> Result<(), XDocErr>
Sets the namespace alias prefix of this element without changing the name. For example, if
the name of this element is ns:foo then set_prefix("xyz:) will change the fullname to xyz:foo`.
Sourcepub fn set_fullname<S: Into<String>>(
&mut self,
fullname: S,
) -> Result<(), XDocErr>
pub fn set_fullname<S: Into<String>>( &mut self, fullname: S, ) -> Result<(), XDocErr>
Sets the fullname of the element. For example, if the name of this element is ns:foo, then
set_fullname("xyz:baz") will set the fullname to xyz:baz. set_fullname("baz") will
eliminate any existing namespace alias prefix and set the fullname to baz.
Sourcepub fn add_attribute<K, V>(&mut self, key: K, value: V) -> Option<String>
pub fn add_attribute<K, V>(&mut self, key: K, value: V) -> Option<String>
Inserts a key-value pair into the attributes map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned.
Sourcepub fn attribute<S: AsRef<str>>(&self, key: S) -> Option<&String>
pub fn attribute<S: AsRef<str>>(&self, key: S) -> Option<&String>
Gets the attribute value at key. None if an attribute by that name does not exist.
Sourcepub fn attributes_len(&self) -> usize
pub fn attributes_len(&self) -> usize
Gets the count of attributes.
Sourcepub fn attributes(&self) -> impl Iterator<Item = (&String, &String)> + '_
pub fn attributes(&self) -> impl Iterator<Item = (&String, &String)> + '_
Gets an iterator over the attribute key/value pairs.
Sourcepub fn attribute_keys(&self) -> impl Iterator<Item = &String> + '_
pub fn attribute_keys(&self) -> impl Iterator<Item = &String> + '_
Gets an iterator over the attribute keys
Sourcepub fn add_new_child(&mut self) -> Result<&mut Element, XDocErr>
pub fn add_new_child(&mut self) -> Result<&mut Element, XDocErr>
Creates a new element as the last child of this element and returns a mut ref to it.
Sourcepub fn add_comment<S: Into<String>>(
&mut self,
comment: S,
) -> Result<(), XDocErr>
pub fn add_comment<S: Into<String>>( &mut self, comment: S, ) -> Result<(), XDocErr>
Append a processing instruction to this element’s nodes.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Does this element have any sub elements. For example, if the element is empty or contains only text and/or pis and/or comments, then false. if the element has elements, then true.
Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns true if there is exactly one sub node, and that sub node is either text or cdata.