[][src]Struct exile::Element

pub struct Element {
    pub namespace: Option<String>,
    pub name: String,
    pub attributes: OrdMap,
    pub nodes: Vec<Node>,
}

Represents an Element in an XML Document.

Fields

namespace: Option<String>

The namespace of this element. e.g. in foo:bar, foo is the namespace.

name: String

The name of this element. e.g. in foo:bar, bar is the name.

attributes: OrdMap

Attributes of this element.

nodes: Vec<Node>

Children of this element.

Implementations

impl Element[src]

pub fn from_name<S: AsRef<str>>(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 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 fullname(&self) -> String[src]

The fullname of the element (including both the namespace and the name).

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

Sets the name of this element.

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 add_new_child(&mut self) -> Result<&mut Element, XErr>[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 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<(), XErr> where
    W: Write
[src]

Write the element to the Write object.

Trait Implementations

impl Clone for Element[src]

impl Debug for Element[src]

impl Default for Element[src]

impl Eq for Element[src]

impl<'a> From<&'a Element> for Cow<'a, Element>[src]

impl<'a> From<Element> for Cow<'a, Element>[src]

impl Hash for Element[src]

impl PartialEq<Element> for Element[src]

impl PartialOrd<Element> 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]

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.