Struct xml::Element
[-] [+]
[src]
pub struct Element { pub name: String, pub ns: Option<String>, pub attributes: HashMap<(String, Option<String>), String>, pub children: Vec<Xml>, // some fields omitted }
A struct representing an XML element
Fields
name | The element's name |
ns | The element's namespace |
attributes | The element's attributes |
children | The element's child |
Methods
impl Element
fn new(name: String, ns: Option<String>, attrs: Vec<(String, Option<String>, String)>) -> Element
Create a new Element
, with specified name and namespace.
Attributes are specified as a Vec
of (name, namespace, value)
tuples.
fn content_str(&self) -> String
Returns the character and CDATA contained in the element.
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.
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.
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.
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.
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.
fn tag(&mut self, child: Element) -> &mut Element
Appends a child element. Returns a reference to the added element.
fn tag_stay(&mut self, child: Element) -> &mut Element
Appends a child element. Returns a mutable reference to self.
fn text(&mut self, text: String) -> &mut Element
Appends characters. Returns a mutable reference to self.
fn cdata(&mut self, text: String) -> &mut Element
Appends CDATA. Returns a mutable reference to self.
fn comment(&mut self, text: String) -> &mut Element
Appends a comment. Returns a mutable reference to self.
fn pi(&mut self, text: String) -> &mut Element
Appends processing information. Returns a mutable reference to self.