xml

Struct Element

source
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

source

pub fn new<A>(name: String, ns: Option<String>, attrs: A) -> Element
where A: IntoIterator<Item = (String, Option<String>, String)>,

Create a new Element, with specified name and namespace. Attributes are specified as a Vec of (name, namespace, value) tuples.

source

pub fn content_str(&self) -> String

Returns the character and CDATA contained in the element.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn tag(&mut self, child: Element) -> &mut Element

Appends a child element. Returns a reference to the added element.

source

pub fn tag_stay(&mut self, child: Element) -> &mut Element

Appends a child element. Returns a mutable reference to self.

source

pub fn text(&mut self, text: String) -> &mut Element

Appends characters. Returns a mutable reference to self.

source

pub fn cdata(&mut self, text: String) -> &mut Element

Appends CDATA. Returns a mutable reference to self.

source

pub fn comment(&mut self, text: String) -> &mut Element

Appends a comment. Returns a mutable reference to self.

source

pub fn pi(&mut self, text: String) -> &mut Element

Appends processing information. Returns a mutable reference to self.

Trait Implementations§

source§

impl Clone for Element

source§

fn clone(&self) -> Element

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Element

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Element

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Element

source§

type Err = BuilderError

The associated error which can be returned from parsing.
source§

fn from_str(data: &str) -> Result<Element, BuilderError>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Element

source§

fn eq(&self, other: &Element) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Element

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.