Struct xmltree::Element[][src]

pub struct Element {
    pub prefix: Option<String>,
    pub namespace: Option<String>,
    pub namespaces: Option<Namespace>,
    pub name: String,
    pub attributes: AttributeMap<String, String>,
    pub children: Vec<XMLNode>,

Represents an XML element.


prefix: Option<String>

This elements prefix, if any

namespace: Option<String>

This elements namespace, if any

namespaces: Option<Namespace>

The full list of namespaces, if any

The Namespace type is exported from the xml-rs crate.

name: String

The name of the Element. Does not include any namespace info

attributes: AttributeMap<String, String>

The Element attributes

By default, this is a HashMap, but if the optional “attribute-order” feature is enabled, this is an IndexMap, which will retain item insertion order.

children: Vec<XMLNode>



impl Element[src]

pub fn new(name: &str) -> Element[src]

Create a new empty element with given name

All other fields are empty

pub fn parse_all<R: Read>(r: R) -> Result<Vec<XMLNode>, ParseError>[src]

Parses some data into a list of XMLNodes

This is useful when you want to capture comments or processing instructions that appear before or after the root node

pub fn parse<R: Read>(r: R) -> Result<Element, ParseError>[src]

Parses some data into an Element

pub fn write<W: Write>(&self, w: W) -> Result<(), Error>[src]

Writes out this element as the root element in an new XML document

pub fn write_with_config<W: Write>(
    w: W,
    config: EmitterConfig
) -> Result<(), Error>

Writes out this element as the root element in a new XML document using the provided configuration

pub fn get_child<P: ElementPredicate>(&self, k: P) -> Option<&Element>[src]

Find a child element with the given name and return a reference to it.

Both &str and String implement ElementPredicate and can be used to search for child elements that match the given element name with .get_child("element_name"). You can also search by ("element_name", "tag_name") tuple.

Note: this will only return Elements. To get other nodes (like comments), iterate through the children field.

pub fn get_mut_child<P: ElementPredicate>(
    &mut self,
    k: P
) -> Option<&mut Element>

Find a child element with the given name and return a mutable reference to it.

pub fn take_child<P: ElementPredicate>(&mut self, k: P) -> Option<Element>[src]

Find a child element with the given name, remove and return it.

pub fn get_text<'a>(&'a self) -> Option<Cow<'a, str>>[src]

Returns the inner text/cdata of this element, if any.

If there are multiple text/cdata nodes, they will be all concatenated into one string.

Trait Implementations

impl Clone for Element[src]

impl Debug for Element[src]

impl Eq for Element[src]

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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.