[][src]Struct roxmltree::Node

pub struct Node<'a, 'input: 'a> { /* fields omitted */ }

A node.

Methods

impl<'a, 'input: 'a> Node<'a, 'input>[src]

pub fn node_type(&self) -> NodeType[src]

Returns node's type.

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

Checks that node is a root node.

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

Checks that node is an element node.

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

Checks that node is a processing instruction node.

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

Checks that node is a comment node.

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

Checks that node is a text node.

pub fn document(&self) -> &'a Document<'input>[src]

Returns node's document.

pub fn tag_name(&self) -> ExpandedName<'a>[src]

Returns node's tag name.

Returns an empty name with no namespace if the current node is not an element.

Examples

let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().tag_name().namespace(), Some("http://www.w3.org"));
assert_eq!(doc.root_element().tag_name().name(), "e");

pub fn has_tag_name<'n, N>(&self, name: N) -> bool where
    N: Into<ExpandedName<'n>>, 
[src]

Checks that node has a specified tag name.

Examples

let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

assert!(doc.root_element().has_tag_name("e"));
assert!(doc.root_element().has_tag_name(("http://www.w3.org", "e")));

assert!(!doc.root_element().has_tag_name("b"));
assert!(!doc.root_element().has_tag_name(("http://www.w4.org", "e")));

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

Returns node's default namespace URI.

Examples

let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().default_namespace(), Some("http://www.w3.org"));
let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().default_namespace(), None);

pub fn lookup_prefix(&self, uri: &str) -> Option<&'a str>[src]

Returns a prefix for a given namespace URI.

Examples

let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().lookup_prefix("http://www.w3.org"), Some("n"));
let doc = roxmltree::Document::parse("<e xmlns:n=''/>").unwrap();

assert_eq!(doc.root_element().lookup_prefix(""), Some("n"));

pub fn lookup_namespace_uri(&self, prefix: Option<&'a str>) -> Option<&'a str>[src]

Returns an URI for a given prefix.

Examples

let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().lookup_namespace_uri(Some("n")), Some("http://www.w3.org"));
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

assert_eq!(doc.root_element().lookup_namespace_uri(None), Some("http://www.w3.org"));

pub fn attribute<'n, N>(&self, name: N) -> Option<&'a str> where
    N: Into<ExpandedName<'n>>, 
[src]

Returns element's attribute value.

Examples

let doc = roxmltree::Document::parse("<e a='b'/>").unwrap();

assert_eq!(doc.root_element().attribute("a"), Some("b"));
let doc = roxmltree::Document::parse(
    "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();

assert_eq!(doc.root_element().attribute("a"), Some("b"));
assert_eq!(doc.root_element().attribute(("http://www.w3.org", "a")), Some("c"));

pub fn attribute_node<'n, N>(&self, name: N) -> Option<&'a Attribute<'input>> where
    N: Into<ExpandedName<'n>>, 
[src]

Returns element's attribute object.

The same as attribute(), but returns the Attribute itself instead of a value string.

pub fn has_attribute<'n, N>(&self, name: N) -> bool where
    N: Into<ExpandedName<'n>>, 
[src]

Checks that element has a specified attribute.

Examples

let doc = roxmltree::Document::parse(
    "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();

assert!(doc.root_element().has_attribute("a"));
assert!(doc.root_element().has_attribute(("http://www.w3.org", "a")));

assert!(!doc.root_element().has_attribute("b"));
assert!(!doc.root_element().has_attribute(("http://www.w4.org", "a")));

pub fn attributes(&self) -> &'a [Attribute<'input>][src]

Returns element's attributes.

Examples

let doc = roxmltree::Document::parse(
    "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>"
).unwrap();

assert_eq!(doc.root_element().attributes().len(), 2);

pub fn namespaces(&self) -> &'a [Namespace<'input>][src]

Returns element's namespaces.

Examples

let doc = roxmltree::Document::parse(
    "<e xmlns:n='http://www.w3.org'/>"
).unwrap();

assert_eq!(doc.root_element().namespaces().len(), 1);

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

Returns node's text.

  • for an element will return a first text child
  • for a comment will return a self text
  • for a text node will return a self text

Examples

let doc = roxmltree::Document::parse("\
<p>
    text
</p>
").unwrap();

assert_eq!(doc.root_element().text(),
           Some("\n    text\n"));
assert_eq!(doc.root_element().first_child().unwrap().text(),
           Some("\n    text\n"));
let doc = roxmltree::Document::parse("<!-- comment --><e/>").unwrap();

assert_eq!(doc.root().first_child().unwrap().text(), Some(" comment "));

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

Returns element's tail text.

Examples

let doc = roxmltree::Document::parse("\
<root>
    text1
    <p/>
    text2
</root>
").unwrap();

let p = doc.descendants().find(|n| n.has_tag_name("p")).unwrap();
assert_eq!(p.tail(), Some("\n    text2\n"));

pub fn pi(&self) -> Option<PI<'input>>[src]

Returns node as Processing Instruction.

pub fn parent(&self) -> Option<Self>[src]

Returns the parent of this node.

pub fn parent_element(&self) -> Option<Self>[src]

Returns the parent element of this node.

pub fn prev_sibling(&self) -> Option<Self>[src]

Returns the previous sibling of this node.

pub fn prev_sibling_element(&self) -> Option<Self>[src]

Returns the previous sibling element of this node.

pub fn next_sibling(&self) -> Option<Self>[src]

Returns the next sibling of this node.

pub fn next_sibling_element(&self) -> Option<Self>[src]

Returns the next sibling element of this node.

pub fn first_child(&self) -> Option<Self>[src]

Returns the first child of this node.

pub fn first_element_child(&self) -> Option<Self>[src]

Returns the first element child of this node.

pub fn last_child(&self) -> Option<Self>[src]

Returns the last child of this node.

pub fn last_element_child(&self) -> Option<Self>[src]

Returns the last element child of this node.

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

Returns true if this node has siblings.

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

Returns true if this node has children.

pub fn ancestors(&self) -> AxisIter<'a, 'input>[src]

Returns an iterator over ancestor nodes starting at this node.

pub fn prev_siblings(&self) -> AxisIter<'a, 'input>[src]

Returns an iterator over previous sibling nodes starting at this node.

pub fn next_siblings(&self) -> AxisIter<'a, 'input>[src]

Returns an iterator over next sibling nodes starting at this node.

pub fn first_children(&self) -> AxisIter<'a, 'input>[src]

Returns an iterator over first children nodes starting at this node.

pub fn last_children(&self) -> AxisIter<'a, 'input>[src]

Returns an iterator over last children nodes starting at this node.

pub fn children(&self) -> Children<'a, 'input>[src]

Returns an iterator over children nodes.

pub fn traverse(&self) -> Traverse<'a, 'input>[src]

Returns an iterator which traverses the subtree starting at this node.

pub fn descendants(&self) -> Descendants<'a, 'input>[src]

Returns an iterator over this node and its descendants.

pub fn range(&self) -> Range<usize>[src]

Returns node's range in bytes in the original document.

Trait Implementations

impl<'a, 'input: 'a> Clone for Node<'a, 'input>[src]

impl<'a, 'input: 'a> Copy for Node<'a, 'input>[src]

impl<'a, 'input: 'a> Debug for Node<'a, 'input>[src]

impl<'a, 'input> Eq for Node<'a, 'input>[src]

impl<'a, 'input> PartialEq<Node<'a, 'input>> for Node<'a, 'input>[src]

Auto Trait Implementations

impl<'a, 'input> !RefUnwindSafe for Node<'a, 'input>

impl<'a, 'input> !Send for Node<'a, 'input>

impl<'a, 'input> !Sync for Node<'a, 'input>

impl<'a, 'input> Unpin for Node<'a, 'input> where
    'input: 'a, 

impl<'a, 'input> !UnwindSafe for Node<'a, 'input>

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.