[][src]Struct roxmltree::Document

pub struct Document<'input> { /* fields omitted */ }

An XML tree container.

A tree consists of Nodes. There are no separate structs for each node type. So you should check the current node type yourself via Node::node_type(). There are only 5 types: Root, Element, PI, Comment and Text.

As you can see there are no XML declaration and CDATA types. The XML declaration is basically skipped, since it doesn't contain any valuable information (we support only UTF-8 anyway). And CDATA will be converted into a Text node as is, without any preprocessing (you can read more about it here).

Also, the Text node data can be accessed from the text node itself or from the parent element via Node::text() or Node::tail().

Methods

impl<'input> Document<'input>[src]

pub fn parse(text: &str) -> Result<Document, Error>[src]

Parses the input XML string.

We do not support &[u8] or Reader because the input must be an already allocated UTF-8 string.

Examples

let doc = roxmltree::Document::parse("<e/>").unwrap();
assert_eq!(doc.descendants().count(), 2); // root node + `e` element node

impl<'input> Document<'input>[src]

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

Returns the root node.

Examples

let doc = roxmltree::Document::parse("<e/>").unwrap();
assert!(doc.root().is_root());
assert!(doc.root().first_child().unwrap().has_tag_name("e"));

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

Returns the root element of the document.

Unlike root, will return a first element node.

The root element always exists.

Examples

let doc = roxmltree::Document::parse("<!-- comment --><e/>").unwrap();
assert!(doc.root_element().has_tag_name("e"));

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

Returns an iterator over document's descendant nodes.

Shorthand for doc.root().descendants().

pub fn text_pos_at(&self, pos: usize) -> TextPos[src]

Calculates TextPos in the original document from position in bytes.

Note: this operation is expensive.

Examples

use roxmltree::*;

let doc = Document::parse("\
<!-- comment -->
<e/>"
).unwrap();

assert_eq!(doc.text_pos_at(10), TextPos::new(1, 11));
assert_eq!(doc.text_pos_at(9999), TextPos::new(2, 5));

Trait Implementations

impl<'input> Debug for Document<'input>[src]

Auto Trait Implementations

impl<'input> !Send for Document<'input>

impl<'input> !Sync for Document<'input>

impl<'input> Unpin for Document<'input>

impl<'input> UnwindSafe for Document<'input>

impl<'input> !RefUnwindSafe for Document<'input>

Blanket Implementations

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

impl<T> From<T> for T[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.

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]