[][src]Enum minidom::node::Node

pub enum Node {
    Element(Element),
    Text(String),
}

A node in an element tree.

Variants

Element(Element)

An Element.

Text(String)

A text node.

Implementations

impl Node[src]

pub fn as_element(&self) -> Option<&Element>[src]

Turns this into a reference to an Element if this is an element node. Else this returns None.

Examples

use minidom::Node;

let elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let txt = Node::Text("meow".to_owned());

assert_eq!(elm.as_element().unwrap().name(), "meow");
assert_eq!(txt.as_element(), None);

pub fn as_element_mut(&mut self) -> Option<&mut Element>[src]

Turns this into a mutable reference of an Element if this is an element node. Else this returns None.

Examples

use minidom::Node;

let mut elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let mut txt = Node::Text("meow".to_owned());

assert_eq!(elm.as_element_mut().unwrap().name(), "meow");
assert_eq!(txt.as_element_mut(), None);

pub fn into_element(self) -> Option<Element>[src]

Turns this into an Element, consuming self, if this is an element node. Else this returns None.

Examples

use minidom::Node;

let elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let txt = Node::Text("meow".to_owned());

assert_eq!(elm.into_element().unwrap().name(), "meow");
assert_eq!(txt.into_element(), None);

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

Turns this into an &str if this is a text node. Else this returns None.

Examples

use minidom::Node;

let elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let txt = Node::Text("meow".to_owned());

assert_eq!(elm.as_text(), None);
assert_eq!(txt.as_text().unwrap(), "meow");

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

Turns this into an &mut String if this is a text node. Else this returns None.

Examples

use minidom::Node;

let mut elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let mut txt = Node::Text("meow".to_owned());

assert_eq!(elm.as_text_mut(), None);
{
    let text_mut = txt.as_text_mut().unwrap();
    assert_eq!(text_mut, "meow");
    text_mut.push_str("zies");
    assert_eq!(text_mut, "meowzies");
}
assert_eq!(txt.as_text().unwrap(), "meowzies");

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

Turns this into an String, consuming self, if this is a text node. Else this returns None.

Examples

use minidom::Node;

let elm = Node::Element("<meow xmlns=\"ns1\"/>".parse().unwrap());
let txt = Node::Text("meow".to_owned());

assert_eq!(elm.into_text(), None);
assert_eq!(txt.into_text().unwrap(), "meow");

Trait Implementations

impl Clone for Node[src]

impl Debug for Node[src]

impl Eq for Node[src]

impl<'a> From<&'a str> for Node[src]

impl From<ElementBuilder> for Node[src]

impl<I> From<I> for Node where
    I: Into<Element>, 
[src]

impl From<String> for Node[src]

impl PartialEq<Node> for Node[src]

impl StructuralEq for Node[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, 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.