SVG::DOM(3)
π SVG::DOM π
okay bestie, so this is the manual page for SVG::DOM, from the User Contributed Perl Documentation section of the manual (section 3, if you were wondering π«Ά). it's a whole library, it's iconic, and we're gonna walk through it together.
β¨ NAME β¨
SVG::DOM β a library of DOM (Document Object Model) methods for SVG objects. that's it, that's the name, and honestly? it ate. π
πΈ SUMMARY πΈ
so basically, SVG::DOM hands you a whole lil' selection of methods for accessing and manipulating SVG elements through DOM-like methods, like getElements, getChildren, getNextSibling, and so on and so on. it's giving "tree traversal but make it cute". π³β¨
π¦ SYNOPSIS π¦
here's the vibe check, verbatim, no cap:
my $svg=SVG->new(id=>"svg_dom_synopsis", width=>"100", height=>"100");
my %attributes=$svg->getAttributes;
my $group=$svg->group(id=>"group_1");
my $name=$group->getElementName;
my $id=$group->getElementID;
$group->circle(id=>"circle_1", cx=>20, cy=>20, r=>5, fill=>"red");
my $rect=$group->rect(id=>"rect_1", x=>10, y=>10, width=>20, height=>30);
my $width=$rect->getAttribute("width");
my $has_children=$group->hasChildren();
my @children=$group->getChildren();
my $kid=$group->getFirstChild();
do {
print $kid->xmlify();
} while ($kid=$kid->getNextSibling);
my @ancestors=$rect->getParents();
my $is_ancestor=$group->isAncestor($rect);
my $is_descendant=$rect->isDescendant($svg);
my @rectangles=$svg->getElements("rect");
my $allelements_arrayref=$svg->getElements();
$group->insertBefore($newChild,$rect);
$group->insertAfter($newChild,$rect);
$rect = $group->replaceChild($newChild,$rect);
$group->removeChild($newChild);
my $newRect = $rect->cloneNode($deep);
...and so on...
like, look at her go. ππ
π METHODS π
this is the main character section, buckle up. π
@elements = $obj->getElements($element_name)
returns a list of all elements with the specified name (i.e. the type) in the document. if you don't pass an element name at all? you get a list of every single element in the document. and if you call it in scalar context, it hands you back an array reference instead. versatile queen. π
@children = $obj->getChildren()
returns a list of all children defined on the current node, or undef if there are literally no children. in scalar context it returns an array reference.
Alias: getChildElements(), getChildNodes()
@children = $obj->hasChildren()
returns 1 if the current node has children, or 0 if there are no children. yes it's basically a vibe check for "do you have kids". π§
Alias: hasChildElements, hasChildNodes()
$ref = $obj->getFirstChild()
returns the first child element of the current node, or undef if there are no children.
$ref = $obj->getLastChild()
returns the last child element of the current node, or undef if there are no children.
$ref = $obj->getSiblings()
returns a list of all children defined on the parent node, containing the current node. the whole friend group, basically. π«Ά
$ref = $obj->getNextSibling()
returns the next child element of the parent node, or undef if this is the last child.
$ref = $obj->getPreviousSibling()
returns the previous child element of the parent node, or undef if this is the first child.
$index = $obj->getChildIndex()
returns the place of this element in the parent node's list of children, starting from 0. zero-indexed, as the ancients intended. π
$element = $obj->getChildAtIndex($index)
returns the child element at the specified index in the parent node's list of children.
$ref = $obj->getParentElement()
returns the parent of the current node. π«
Alias: getParent()
@refs = $obj->getParentElements()
returns a list of the parents of the current node, starting from the immediate parent. the last member of the list should be the document element.
Alias: getParents()
$name = $obj->getElementName()
returns a string containing the name (i.e. the type, not the ID) of an element.
Alias: getType(), getTagName(), getNodeName()
$ref = $svg->getElementByID($id)
Alias: getElementbyID()
returns a reference to the element which has ID $id, or undef if no element with this ID exists. (yes, the alias comes first, that's just how she is. π
)
$id = $obj->getElementID()
returns a string containing the ID of the current node, or undef if it has no ID.
$ref = $obj->getAttributes()
returns a hash reference of attribute names and values for the current node.
$value = $obj->getAttribute($name);
returns the string value attribute value for an attribute of name $name.
$ref = $obj->setAttributes({name1=>$value1,name2=>undef,name3=>$value3})
sets a whole set of attributes at once. if $value is undef, it deletes the attribute. bye bestie π
$value = $obj->setAttribute($name,$value);
sets attribute $name to $value. if $value is undef, it deletes the attribute. same energy, one at a time.
$cdata = $obj->getCDATA()
returns the canonical data (i.e. the textual content) of the current node.
Alias: getCdata(), getData()
$boolean = $obj->isAncestor($element)
returns 1 if the current node is an ancestor of the specified element, otherwise 0.
$boolean = $obj->isDescendant($element)
returns 1 if the current node is a descendant of the specified element, otherwise 0.
$boolean = $obj->insertBefore( $element, $child );
returns 1 if $element was successfully inserted before $child in $obj
$boolean = $obj->insertAfter( $element, $child );
returns 1 if $element was successfully inserted after $child in $obj
$boolean = $obj->insertSiblingBefore( $element );
returns 1 if $element was successfully inserted before $obj
$boolean = $obj->insertSiblingAfter( $element );
returns 1 if $element was successfully inserted after $obj
$element = $obj->replaceChild( $element, $child );
returns $child if $element successfully replaced $child in $obj
$element = $obj->removeChild( $child );
returns $child if it was removed successfully from $obj. it's not you, it's the DOM. π
$element = $obj->cloneNode( $deep );
returns a new $element clone of $obj, without parents or children. if $deep is set to 1, all children are included recursively. multitudes contained. β¨
π AUTHOR π
Ronan Oger, ronan@roitsystems.com Martin Owens, doctormo@postmaster.co.uk
(not me giving credit where it's due, as I should π«‘)
π SEE ALSO π
perl(1),SVG,SVG::XML,SVG::Element,SVG::Parser- <http://www.w3c.org/Graphics/SVG/> β SVG at the W3C
and that's the whole page, bestie!! π this was SVG::DOM(3) from perl v5.42.0, dated 2026-03-13, in the User Contributed Perl Documentation section. go forth and traverse those nodes, you absolute icon. πβ¨π¦
π¦ where this page comes from
- fedora 44: perl-SVG 2.89-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms