Struct svgdom::Document
[−]
[src]
pub struct Document { pub root: Node, }
Container of Node
s.
Fields
root: Node
Root node.
Methods
impl Document
[src]
fn new() -> Document
[src]
Constructs a new Document
.
fn from_str(text: &str) -> Result<Document, Error>
[src]
Constructs a new Document
from the text using a default ParseOptions
.
fn from_str_with_opt(text: &str, opt: &ParseOptions) -> Result<Document, Error>
[src]
Constructs a new Document
from the text using a supplied ParseOptions
.
fn create_element<'a, T>(&mut self, tag_name: T) -> Node where
TagNameRef<'a>: From<T>,
[src]
TagNameRef<'a>: From<T>,
Constructs a new Node
with NodeType
::Element type.
Constructed node do belong to this document, but not added to it tree structure.
Panics
Panics if a string tag name is empty.
fn create_node(&mut self, node_type: NodeType, text: &str) -> Node
[src]
Constructs a new Node
using the supplied NodeType
.
Constructed node do belong to this document, but not added to it tree structure.
This method should be used for any non-element nodes.
fn root(&self) -> Node
[src]
Returns the root Node
.
fn first_child(&self) -> Option<Node>
[src]
Returns the first child of the root Node
.
Panics
Panics if the root node is currently mutability borrowed.
fn svg_element(&self) -> Option<Node>
[src]
Returns the first child with svg
tag name of the root Node
.
In most of the cases result of this method and first_element_child()
will be the same,
but an additional check may be helpful.
Panics
Panics if the root node is currently mutability borrowed.
Examples
use svgdom::{Document, ElementId}; let doc = Document::from_str("<!--comment--><svg/>").unwrap(); assert_eq!(doc.svg_element().unwrap().is_tag_name(ElementId::Svg), true);
fn append(&mut self, new_child: &Node) -> Node
[src]
Appends a new child to root node, after existing children, and returns it.
Panics
Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.
Examples
use svgdom::{Document, ElementId}; let mut doc = Document::new(); let svg = doc.create_element(ElementId::Svg); doc.append(&svg); assert_eq!(doc.to_string(), "<svg/>\n");
fn descendants(&self) -> Descendants
[src]
Returns an iterator over descendants.
fn children(&self) -> Children
[src]
Returns an iterator to this node's children elements.
Panics
Panics if the node is currently mutability borrowed.
fn drain<P>(&mut self, f: P) -> usize where
P: Fn(&Node) -> bool,
[src]
P: Fn(&Node) -> bool,
Removes only the children nodes specified by the predicate.
The root node ignored.
Trait Implementations
impl WriteBuffer for Document
[src]
fn write_buf_opt(&self, opt: &WriteOptions, buf: &mut Vec<u8>)
[src]
Writes data to the Vec<u8>
buffer using specified WriteOptions
.
fn write_buf(&self, buf: &mut Vec<u8>)
[src]
Writes data to the Vec<u8>
buffer using default WriteOptions
.
impl Display for Document
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl ToStringWithOptions for Document
[src]
fn to_string_with_opt(&self, opt: &WriteOptions) -> String
[src]
Writes data to the String
using specified WriteOptions
.