Struct exile::Element[][src]

pub struct Element { /* fields omitted */ }
Expand description

Represents an Element in an XML Document.

Implementations

impl Element[src]

pub fn from_name<S: Into<String>>(name: S) -> Self[src]

Create a new element using the given name.

pub fn children(&self) -> impl Iterator<Item = &Element>[src]

Returns the ‘child’ elements of the current element. Consider the XML document:

<r>
  <a/>
  <b/>
</r>

r’s children() function would return an iterator over ‘a’ and ‘b’. Text nodes, processing instructions and comments are skipped/ignored by the iterator.

pub fn children_mut(&mut self) -> impl Iterator<Item = &mut Element>[src]

Returns the ‘child’ elements of the current element. Consider the XML document:

<r>
  <a/>
  <b/>
</r>

r’s children_mut() function would return an iterator over ‘a’ and ‘b’. Text nodes, processing instructions and comments are skipped/ignored by the iterator.

pub fn child<S: AsRef<str>>(&self, name: S) -> Option<&Element>[src]

Find the first occurrance specific child element (does not recurse to lower levels of children).

pub fn add_child(&mut self, element: Element)[src]

Add an element as a child of this element.

pub fn add_cdata<S: Into<String>>(&mut self, cdata: S) -> Result<(), XDocErr>[src]

Add a CDATA node. Will error if the string contains ]]> as this cannot be represented in a CDATA node.

pub fn nodes_len(&self) -> usize[src]

Get the number of nodes (of any kind) that are children of this node.

pub fn first_node(&self) -> Option<&Node>[src]

Get the first child node (of any kind)

pub fn node(&self, index: usize) -> Option<&Node>[src]

Get the child node (of any kind) at index.

pub fn fullname(&self) -> &str[src]

The fullname of the element (including both the namespace alias prefix and the name). For example, if the name of this element is ns:foo, this function returns "ns:foo". Element::name and [Element:prefix] give the parsed sections of the fullname.

pub fn name(&self) -> &str[src]

The name of the element without its prefix. For example, if the name of this element is ns:foo, name() will return foo.

pub fn prefix(&self) -> Option<&str>[src]

The name of the element’s namespace alias prefix. For example, if the name of this element is ns:foo, prefix() will return Some("ns").

pub fn set_name<S: AsRef<str>>(&mut self, name: S)[src]

Sets the name of this element without changing the namespace alias prefix. For example, if the name of this element is ns:foo then set_name("bar") will change the fullname to ns:bar.

pub fn set_prefix<S: AsRef<str>>(&mut self, prefix: S) -> Result<(), XDocErr>[src]

Sets the namespace alias prefix of this element without changing the name. For example, if the name of this element is ns:foo then set_prefix("xyz:) will change the fullname to xyz:foo`.

pub fn set_fullname<S: Into<String>>(
    &mut self,
    fullname: S
) -> Result<(), XDocErr>
[src]

Sets the fullname of the element. For example, if the name of this element is ns:foo, then set_fullname("xyz:baz") will set the fullname to xyz:baz. set_fullname("baz") will eliminate any existing namespace alias prefix and set the fullname to baz.

pub fn add_attribute<K, V>(&mut self, key: K, value: V) -> Option<String> where
    K: AsRef<str>,
    V: AsRef<str>, 
[src]

Inserts a key-value pair into the attributes map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

pub fn attribute<S: AsRef<str>>(&self, key: S) -> Option<&String>[src]

Gets the attribute value at key. None if an attribute by that name does not exist.

pub fn attributes_len(&self) -> usize[src]

Gets the count of attributes.

pub fn attributes(&self) -> impl Iterator<Item = (&String, &String)> + '_[src]

Gets an iterator over the attribute key/value pairs.

pub fn attribute_keys(&self) -> impl Iterator<Item = &String> + '_[src]

Gets an iterator over the attribute keys

pub fn add_new_child(&mut self) -> Result<&mut Element, XDocErr>[src]

Creates a new element as the last child of this element and returns a mut ref to it.

pub fn add_text<S: AsRef<str>>(&mut self, text: S)[src]

Append a text node to this element’s nodes.

pub fn add_pi(&mut self, pi: Pi)[src]

Append a processing instruction to this element’s nodes.

pub fn add_comment<S: Into<String>>(
    &mut self,
    comment: S
) -> Result<(), XDocErr>
[src]

Append a processing instruction to this element’s nodes.

pub fn has_children(&self) -> bool[src]

Does this element have any sub elements. For example, if the element is empty or contains only text and/or pis and/or comments, then false. if the element has elements, then true.

pub fn is_text(&self) -> bool[src]

Returns true if there is exactly one sub node, and that sub node is either text or cdata.

pub fn text(&self) -> Option<String>[src]

Returns the contents of the first Text or CData node encountered in the element. Useful for simple ‘text’ elements like <something>text is here</something> where this function will return Some("text is here").

pub fn write<W>(
    &self,
    writer: &mut W,
    opts: &WriteOpts,
    depth: usize
) -> Result<(), XDocErr> where
    W: Write
[src]

Write the element to the Write object.

Trait Implementations

impl Clone for Element[src]

fn clone(&self) -> Element[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Element[src]

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

Formats the value using the given formatter. Read more

impl Default for Element[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl Display for Element[src]

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

Formats the value using the given formatter. Read more

impl Hash for Element[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl Ord for Element[src]

fn cmp(&self, other: &Element) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Element> for Element[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Element) -> bool[src]

This method tests for !=.

impl PartialOrd<Element> for Element[src]

fn partial_cmp(&self, other: &Element) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Eq for Element[src]

impl StructuralEq for Element[src]

impl StructuralPartialEq for Element[src]

Auto Trait Implementations

impl RefUnwindSafe for Element

impl Send for Element

impl Sync for Element

impl Unpin for Element

impl UnwindSafe for Element

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.