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.
Trait Implementations§
impl StructuralPartialEq for Element
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)