Struct svgdom::Document[][src]

pub struct Document { /* fields omitted */ }

Container of Nodes.

Structure:

The Document itself is just a container of Nodes. You can create new Nodes 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]

Constructs a new Document.

Constructs a new Document from the text using a default ParseOptions.

Note: only SVG elements and attributes will be parsed.

Constructs a new Document from the text using a supplied ParseOptions.

Note: only SVG elements and attributes will be parsed.

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.

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.

Returns the root Node.

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().is_tag_name(ElementId::Svg), true);

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'>
    <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.is_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);

Removes only the children nodes specified by the predicate.

Uses remove(), not detach() internally.

The root node will be ignored.

Returns a copy of a current node without children.

All attributes except id will be copied, because id must be unique.

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

impl WriteBuffer for Document
[src]

Writes data to the Vec<u8> buffer using specified WriteOptions.

Writes data to the Vec<u8> buffer using default WriteOptions.

Returns an object that implements fmt::Display using provided write options.

impl Drop for Document
[src]

Executes the destructor for this type. Read more

impl Display for Document
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl !Send for Document

impl !Sync for Document