[][src]Struct exile::Element

pub struct Element { /* fields omitted */ }

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

impl Debug for Element[src]

impl Default for Element[src]

impl Display for Element[src]

impl Eq for Element[src]

impl Hash for Element[src]

impl Ord 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

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> ToString for T where
    T: Display + ?Sized
[src]

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.