1SVG::DOM(3)           User Contributed Perl Documentation          SVG::DOM(3)
2
3
4

NAME

6       SVG::DOM - A library of DOM (Document Object Model) methods for SVG
7       objects.
8

SUMMARY

10       SVG::DOM provides a selection of methods for accessing and manipulating
11       SVG elements through DOM-like methods such as getElements, getChildren,
12       getNextSibling and so on.
13

SYNOPSIS

15           my $svg=new SVG(id=>"svg_dom_synopsis", width=>"100", height=>"100");
16           my %attributes=$svg->getAttributes;
17
18           my $group=$svg->group(id=>"group_1");
19           my $name=$group->getElementName;
20           my $id=$group->getElementID;
21
22           $group->circle(id=>"circle_1", cx=>20, cy=>20, r=>5, fill=>"red");
23           my $rect=$group->rect(id=>"rect_1", x=>10, y=>10, width=>20, height=>30);
24           my $width=$rect->getAttribute("width");
25
26           my $has_children=$group->hasChildren();
27           my @children=$group->getChildren();
28
29           my $kid=$group->getFirstChild();
30           do {
31               print $kid->xmlify();
32           } while ($kid=$kid->getNextSibling);
33
34           my @ancestors=$rect->getParents();
35           my $is_ancestor=$group->isAncestor($rect);
36           my $is_descendant=$rect->isDescendant($svg);
37
38           my @rectangles=$svg->getElements("rect");
39           my $allelements_arrayref=$svg->getElements();
40
41           $group->insertBefore($newChild,$rect);
42           $group->insertAfter($newChild,$rect);
43           $rect = $group->replaceChild($newChild,$rect);
44           $group->removeChild($newChild);
45           my $newRect = $rect->cloneNode($deep);
46
47           ...and so on...
48

METHODS

50   @elements = $obj->getElements($element_name)
51       Return a list of all elements with the specified name (i.e. type) in
52       the document. If no element name is provided, returns a list of all
53       elements in the document.  In scalar context returns an array
54       reference.
55
56   @children = $obj->getChildren()
57       Return a list of all children defined on the current node, or undef if
58       there are no children.  In scalar context returns an array reference.
59
60       Alias: getChildElements(), getChildNodes()
61
62   @children = $obj->hasChildren()
63       Return 1 if the current node has children, or 0 if there are no
64       children.
65
66       Alias: hasChildElements, hasChildNodes()
67
68   $ref = $obj->getFirstChild()
69       Return the first child element of the current node, or undef if there
70       are no children.
71
72   $ref = $obj->getLastChild()
73       Return the last child element of the current node, or undef if there
74       are no children.
75
76   $ref = $obj->getSiblings()
77       Return a list of all children defined on the parent node, containing
78       the current node.
79
80   $ref = $obj->getNextSibling()
81       Return the next child element of the parent node, or undef if this is
82       the last child.
83
84   $ref = $obj->getPreviousSibling()
85       Return the previous child element of the parent node, or undef if this
86       is the first child.
87
88   $index = $obj->getChildIndex()
89       Return the place of this element in the parent node's list of children,
90       starting from 0.
91
92   $element = $obj->getChildAtIndex($index)
93       Returns the child element at the specified index in the parent node's
94       list of children.
95
96   $ref = $obj->getParentElement()
97       Return the parent of the current node.
98
99       Alias: getParent()
100
101   @refs = $obj->getParentElements()
102       Return a list of the parents of the current node, starting from the
103       immediate parent. The last member of the list should be the document
104       element.
105
106       Alias: getParents()
107
108   $name = $obj->getElementName()
109       Return a string containing the name (i.e. the type, not the ID) of an
110       element.
111
112       Alias: getType(), getTagName(), getNodeName()
113
114   $ref = $svg->getElementByID($id)
115       Alias: getElementbyID()
116
117       Return a reference to the element which has ID $id, or undef if no
118       element with this ID exists.
119
120   $id = $obj->getElementID()
121       Return a string containing the ID of the current node, or undef if it
122       has no ID.
123
124   $ref = $obj->getAttributes()
125       Return a hash reference of attribute names and values for the current
126       node.
127
128   $value = $obj->getAttribute($name);
129       Return the string value attribute value for an attribute of name $name.
130
131   $ref = $obj->setAttributes({name1=>$value1,name2=>undef,name3=>$value3})
132       Set a set of attributes. If $value is undef, deletes the attribute.
133
134   $value = $obj->setAttribute($name,$value);
135       Set attribute $name to $value. If $value is undef, deletes the
136       attribute.
137
138   $cdata = $obj->getCDATA()
139       Return the canonical data (i.e. textual content) of the current node.
140
141       Alias: getCdata(), getData()
142
143   $boolean = $obj->isAncestor($element)
144       Returns 1 if the current node is an ancestor of the specified element,
145       otherwise 0.
146
147   $boolean = $obj->isDescendant($element)
148       Returns 1 if the current node is a descendant of the specified element,
149       otherwise 0.
150
151   $boolean = $obj->insertBefore( $element, $child );
152       Returns 1 if $element was successfully inserted before $child in $obj
153
154   $boolean = $obj->insertAfter( $element, $child );
155       Returns 1 if $element was successfully inserted after $child in $obj
156
157   $boolean = $obj->insertSiblingBefore( $element );
158       Returns 1 if $element was successfully inserted before $obj
159
160   $boolean = $obj->insertSiblingAfter( $element );
161       Returns 1 if $element was successfully inserted after $obj
162
163   $element = $obj->replaceChild( $element, $child );
164       Returns $child if $element successfully replaced $child in $obj
165
166   $element = $obj->removeChild( $child );
167       Returns $child if it was removed successfully from $obj
168
169   $element = $obj->cloneNode( $deep );
170       Returns a new $element clone of $obj, without parents or children. If
171       deep is set to 1, all children are included recursively.
172

AUTHOR

174       Ronan Oger, ronan@roitsystems.com Martin Owens,
175       doctormo@postmaster.co.uk
176

SEE ALSO

178       perl(1), SVG, SVG::XML, SVG::Element, SVG::Parser
179
180       <http://www.roitsystems.com/> ROIT Systems: Commercial SVG perl
181       solutions <http://www.w3c.org/Graphics/SVG/> SVG at the W3C
182
183
184
185perl v5.30.0                      2019-07-26                       SVG::DOM(3)
Impressum