Struct svgdom::Document
[−]
[src]
pub struct Document { // some fields omitted }
Container of Node
s.
Methods
impl Document
[src]
fn new() -> Document
Constructs a new Document
.
fn from_data(data: &[u8]) -> Result<Document, Error>
Constructs a new Document
from data
using default ParseOptions
.
fn from_data_with_opt(data: &[u8], opt: &ParseOptions) -> Result<Document, Error>
Constructs a new Document
from data
using supplied ParseOptions
.
fn create_element<T>(&self, tag_name: T) -> Node where TagName: From<T>
Constructs a new Node
with Element
type.
Constructed node do belong to this document, but not added to it tree structure.
fn create_node(&self, node_type: NodeType, text: &str) -> Node
Constructs a new Node
using 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 create_element_with_text<T>(&self, tag_name: T, text: &str) -> Node where TagName: From<T>
Constructs a new element with text node.
Examples
use svgdom::{Document, ElementId}; let doc = Document::new(); doc.append(&doc.create_element_with_text(ElementId::Text, "text")); assert_eq!(doc.to_string(), "<text> text </text> ");
fn root(&self) -> Node
Returns root Node
.
fn first_child(&self) -> Option<Node>
Returns first child of the root Node
.
Panics
Panics if the root node is currently mutability borrowed.
fn first_element_child(&self) -> Option<Node>
Returns first child with NodeType::Element
of the root Node
.
Panics
Panics if the root node is currently mutability borrowed.
Examples
use svgdom::Document; let doc = Document::from_data(b"<!--comment--><svg/>").unwrap(); assert_eq!(doc.first_child().unwrap().is_element(), false); assert_eq!(doc.first_element_child().unwrap().is_element(), true);
fn svg_element(&self) -> Option<Node>
Returns 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_data(b"<!--comment--><svg/>").unwrap(); assert_eq!(doc.svg_element().unwrap().is_tag_id(ElementId::Svg), true);
fn append(&self, new_child: &Node) -> Node
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 doc = Document::new(); doc.append(&doc.create_element(ElementId::Svg)); assert_eq!(doc.to_string(), "<svg/>\n");
fn descendants(&self) -> Descendants
Returns iterator over descendant SVG elements.
fn descendants_all(&self) -> DescendantsAll
Returns iterator over descendant SVG nodes.
Trait Implementations
impl WriteBuffer for Document
[src]
fn write_buf_opt(&self, opt: &WriteOptions, buf: &mut Vec<u8>)
Writes data to Vec<u8>
buffer using specified WriteOptions.
fn write_buf(&self, buf: &mut Vec<u8>)
Writes data to Vec<u8>
buffer using default WriteOptions.
impl Display for Document
[src]
impl WriteToString for Document
[src]
fn to_string_with_opt(&self, opt: &WriteOptions) -> String
Writes data to String
using specified WriteOptions.