pub struct Element {
pub name: String,
pub ns: Option<String>,
pub attributes: HashMap<(String, Option<String>), String>,
pub children: Vec<Xml>,
/* private fields */
}
Expand description
A struct representing an XML element
Fields§
§name: String
The element’s name
ns: Option<String>
The element’s namespace
attributes: HashMap<(String, Option<String>), String>
The element’s attributes
children: Vec<Xml>
The element’s child Xml
nodes
Implementations§
Source§impl Element
impl Element
Sourcepub fn new<A>(name: String, ns: Option<String>, attrs: A) -> Element
pub fn new<A>(name: String, ns: Option<String>, attrs: A) -> Element
Create a new Element
, with specified name and namespace.
Attributes are specified as a Vec
of (name, namespace, value)
tuples.
Sourcepub fn content_str(&self) -> String
pub fn content_str(&self) -> String
Returns the character and CDATA contained in the element.
Sourcepub fn get_attribute<'a>(
&'a self,
name: &str,
ns: Option<&str>,
) -> Option<&'a str>
pub fn get_attribute<'a>( &'a self, name: &str, ns: Option<&str>, ) -> Option<&'a str>
Gets an attribute with the specified name and namespace. When an attribute with the
specified name does not exist None
is returned.
Sourcepub fn set_attribute(
&mut self,
name: String,
ns: Option<String>,
value: String,
) -> Option<String>
pub fn set_attribute( &mut self, name: String, ns: Option<String>, value: String, ) -> Option<String>
Sets the attribute with the specified name and namespace. Returns the original value.
Sourcepub fn remove_attribute(
&mut self,
name: &str,
ns: Option<&str>,
) -> Option<String>
pub fn remove_attribute( &mut self, name: &str, ns: Option<&str>, ) -> Option<String>
Remove the attribute with the specified name and namespace. Returns the original value.
Sourcepub fn get_child<'a>(
&'a self,
name: &str,
ns: Option<&str>,
) -> Option<&'a Element>
pub fn get_child<'a>( &'a self, name: &str, ns: Option<&str>, ) -> Option<&'a Element>
Gets the first child Element
with the specified name and namespace. When no child
with the specified name exists None
is returned.
Sourcepub fn get_children<'a, 'b>(
&'a self,
name: &'b str,
ns: Option<&'b str>,
) -> ChildElements<'a, 'b> ⓘ
pub fn get_children<'a, 'b>( &'a self, name: &'b str, ns: Option<&'b str>, ) -> ChildElements<'a, 'b> ⓘ
Get all children Element
with the specified name and namespace. When no child
with the specified name exists an empty vetor is returned.
Sourcepub fn tag(&mut self, child: Element) -> &mut Element
pub fn tag(&mut self, child: Element) -> &mut Element
Appends a child element. Returns a reference to the added element.
Sourcepub fn tag_stay(&mut self, child: Element) -> &mut Element
pub fn tag_stay(&mut self, child: Element) -> &mut Element
Appends a child element. Returns a mutable reference to self.
Sourcepub fn text(&mut self, text: String) -> &mut Element
pub fn text(&mut self, text: String) -> &mut Element
Appends characters. Returns a mutable reference to self.
Sourcepub fn cdata(&mut self, text: String) -> &mut Element
pub fn cdata(&mut self, text: String) -> &mut Element
Appends CDATA. Returns a mutable reference to self.