Struct quick_xml::Element

source ·
pub struct Element { /* private fields */ }
Expand description

General content of an event (aka node)

Element is a wrapper over the bytes representing the node:

E.g. given a node <name att1="a", att2="b">, the corresponding Event will be

Event::Start(Element {
    buf:    b"name att1=\"a\", att2=\"b\"",
    start:  0,
    end:    b"name att1=\"a\", att2=\"b\"".len(),
    name_end: b"name".len()
})

For performance reasons, most of the time, no character searches but b'<' and b'>' are performed:

  • no attribute parsing: use lazy Attributes iterator only when needed
  • no namespace awareness as it requires parsing all Start element attributes
  • no utf8 conversion: prefer searching statically binary comparisons then use the as_str or into_string methods

Implementations§

source§

impl Element

source

pub fn new<A>(name: A) -> Element
where A: AsRef<[u8]>,

Creates a new Element from the given name. name is a reference that can be converted to a byte slice, such as &u8 or &str

source

pub fn with_attributes<K, V, I>(self, attributes: I) -> Self
where K: AsRef<[u8]>, V: AsRef<[u8]>, I: IntoIterator<Item = (K, V)>,

Consumes self and adds attributes to this element from an iterator over (key, value) tuples. Key and value can be anything that implements the AsRef<u8> trait, like byte slices and strings.

source

pub fn name(&self) -> &[u8]

name as &u8 (without eventual attributes)

source

pub fn content(&self) -> &[u8]

whole content as &u8 (including eventual attributes)

source

pub fn unescaped_content(&self) -> ResultPos<Cow<'_, [u8]>>

gets escaped content

Searches for ‘&’ into content and try to escape the coded character if possible returns Malformed error with index within element if ‘&’ is not followed by ‘;’

source

pub fn attributes(&self) -> Attributes<'_>

gets attributes iterator

source

pub fn unescaped_attributes(&self) -> UnescapedAttributes<'_>

gets attributes iterator whose attribute values are unescaped (‘&…;’ replaced by their corresponding character)

source

pub fn extend_attributes<K, V, I>(&mut self, attributes: I) -> &mut Element
where K: AsRef<[u8]>, V: AsRef<[u8]>, I: IntoIterator<Item = (K, V)>,

extend the attributes of this element from an iterator over (key, value) tuples. Key and value can be anything that implements the AsRef<u8> trait, like byte slices and strings.

source

pub fn into_string(self) -> Result<String>

consumes entire self (including eventual attributes!) and returns String

useful when we need to get Text event value (which don’t have attributes)

source

pub fn push_attribute<K, V>(&mut self, key: K, value: V)
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Adds an attribute to this element from the given key and value. Key and value can be anything that implements the AsRef<u8> trait, like byte slices and strings.

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<(), Error>

Formats the value using the given formatter. Read more

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§

default 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,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.