[−][src]Struct svgdom::Document
Container of Node
s.
Structure:
The Document
itself is just a container of Node
s.
You can create new Node
s only through the Document
.
Parsing and generating of the SVG data also done through it.
The Node
represents any kind of an XML node.
It can be an element, a comment, a text, etc. There are no different structs for each type.
The TagName
represents a tag name of the element node. It's an enum of
ElementId
and String
types. The ElementId
contains all possible
SVG element names and String
used for non-SVG elements. Such separation used for
performance reasons.
The Attributes
container wraps a Vec
of Attribute
's.
At last, the id
attribute is stored as a separate value and not as part of the Attributes
.
Methods
impl Document
[src]
pub fn new() -> Document
[src]
Constructs a new Document
.
pub fn from_str(text: &str) -> Result<Document, ParserError>
[src]
Constructs a new Document
from the text.
Note: only SVG elements and attributes will be parsed.
pub fn to_string_with_opt(&self, opt: &WriteOptions) -> String
[src]
Writes a Document
content to a string.
pub fn create_element<'a, T>(&mut self, tag_name: T) -> Node where
TagNameRef<'a>: From<T>,
T: Copy,
[src]
TagNameRef<'a>: From<T>,
T: Copy,
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.
pub fn create_node<S: Into<String>>(
&mut self,
node_type: NodeType,
text: S
) -> Node
[src]
&mut self,
node_type: NodeType,
text: S
) -> Node
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.
pub fn root(&self) -> Node
[src]
Returns the root Node
.
pub 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 xmlns='http://www.w3.org/2000/svg'/>").unwrap(); assert_eq!(doc.svg_element().unwrap().has_tag_name(ElementId::Svg), true);
pub fn remove_node(&mut self, node: Node)
[src]
Removes this node and all it children from the tree.
Same as detach()
, but also removes all linked attributes from the tree.
Panics
Panics if the node or one of its adjoining nodes or any children node is currently borrowed.
Examples
use svgdom::{Document, ElementId, AttributeId}; let mut doc = Document::from_str( "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'> <rect id='rect1'/> <use xlink:href='#rect1'/> </svg>").unwrap(); let mut rect_elem = doc.root().descendants().filter(|n| *n.id() == "rect1").next().unwrap(); let use_elem = doc.root().descendants().filter(|n| n.has_tag_name(ElementId::Use)).next().unwrap(); assert_eq!(use_elem.has_attribute(AttributeId::Href), true); // The 'remove' method will remove 'rect' element and all it's children. // Also it will remove all links to this element and it's children, // so 'use' element will no longer have the 'xlink:href' attribute. doc.remove_node(rect_elem); assert_eq!(use_elem.has_attribute(AttributeId::Href), false);
pub fn drain<P>(&mut self, root: Node, f: P) -> usize where
P: Fn(&Node) -> bool,
[src]
P: Fn(&Node) -> bool,
Removes only the children nodes specified by the predicate.
Uses remove(), not detach() internally.
The root
node will be ignored.
pub fn copy_node(&mut self, node: Node) -> Node
[src]
Returns a copy of a current node without children.
All attributes except id
will be copied, because id
must be unique.
pub fn copy_node_deep(&mut self, node: Node) -> Node
[src]
Returns a deep copy of a current node with all it's children.
All attributes except id
will be copied, because id
must be unique.
Trait Implementations
Auto Trait Implementations
impl Unpin for Document
impl !Send for Document
impl !Sync for Document
impl !UnwindSafe for Document
impl !RefUnwindSafe for Document
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,