Struct roxmltree::Document[][src]

pub struct Document<'d> { /* 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 contains 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 accesses from the text node itself or from the parent element via Node::text() or Node::tail().

Methods

impl<'d> Document<'d>
[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<'d> Document<'d>
[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"));

Returns the root element of the document.

Unlike root, will return a first element node.

The root element is always exists.

Examples

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

Important traits for Descendants<'a, 'd>

Returns an iterator over document's descendant nodes.

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

Calculates TextPos in the original document from position in bytes.

Note: this operation is expensive.

Examples

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

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

Trait Implementations

impl<'d> PartialEq for Document<'d>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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