View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Martin Owens > XML-DOM2-0.06 > XML::DOM2::DOM::Element



Annotate this POD


New  1
Open  0
View/Report Bugs


XML::DOM2::DOM::Element - A library of DOM (Document Object Model) methods for XML Elements.


Provides all the DOM method for XML Elements




  Returns the elements first child in it's children list



  Returns the elements last child in it's children list

$element->getChildIndex( @children )

  Return the array index of this element in the parent or the passed list (if there is one).

$element->getChildAtIndex( $index )

  Return the element at the specified index (the index can be negative).



  Return the next element to this element in the parents child list.



  Return the previous element to this element in the parents child list.




  Returns all the elements children.

$element->getChildrenByName( $name )

  Returns all the elements children with that tag name (including namespace prefix).




  Returns 1 if this element has children.




  Returns the object of the parent element.

$element->setParent( $element )

$element->setParentElement( $element )


Sets the parent node, used internaly.





  Return a list of the parents of the current element, starting from the immediate parent. The
  last member of the list should be the document element.

$element->isAncestor( $node )

  Returns true if the current element is an ancestor of the descendant element.

$element->isDescendant( $node )

  Return true if the crrent element is the descendant of the ancestor element.


  Returns a list of sibling elements.


  Returns true if the elements has sibling elements.








  Return a string containing the name (i.e. the type, not the Id) of an element.


  Return a string containing the elements Id (unique identifier string).

$element->getAttribute( $attributeName )

  Returns the specified attribute in the element, will return a
  serialised string instead of posible attribute object if serialise set.

$element->getAttributes( $serialise, $ns )

  Returns a list of attributes in various forms.


  Returns a list of attribute names, used internaly.

$element->getAttributeNamesNS( $namespace )

  Returns a list of attribute names, used internaly.


  Returns a list of attribute names, used internaly.

$element->hasAttribute( $attributeName )

  Returns true if this element as this attribute.

$element->hasAttributeNS( $namespace, $attributeName )

  Returns true if this attribute in this namespace is in this element.


  Return true is element has any attributes

$element->setAttribute( $attribute, $value )

  Set an attribute on this element, it will accept serialised strings or objects.

$element->removeAttribute( $name )

  Remove a single attribute from this element.

$element->removeAttributeNS( $namespace, $name )

  Remove a single attribute from this element.

$element->getAttributeNS( $namespace, $name )

  Returns an attributes namespace in this element.

$element->setAttributeNS( $namespace, $name, $value )

  Sets an attributes namespace in this element.

$element->cdata( $text )

  Rerieve and set this elements cdata (non tag cdata form)


  Return true if this element has cdata.


  Return this elements document, returns undef if no document available.

$element->insertBefore( $node, $childNode )

$element->insertChildBefore( $node, $childNode )

$element->insertNodeBefore( $node, $childNode )

$element->insertElementBefore( $node, $childNode )

  Inserts a new element just before the referenced child.

$element->insertAfter( $node, $childNode )

$element->insertChildAfter( $node, $childNode )

$element->insertElementAfter( $node, $childNode )

$element->insertNodeAfter( $node, $childNode )

Inserts a new child element just after the referenced child.

$element->insertSiblingAfter( $node )

  Inserts the child just after the current element (effects parent).

$element->insertSiblingBefore( $node )

  Inserts the child just before the current element (effects parent).

$element->replaceChild( $newChild, $oldChild )

  Replace an old child with a new element, returns old element.

$element->replaceElement( $newElement )

$element->replaceNode( $newElement )

  Replace an old element with a new element in the parents context; element becomes orphaned.

$element->removeChild( $child )

  Remove a child from this element, returns the orphaned element.



  Removes this element from it's parent; element becomes orphaned.

$element->appendChild( $node )

$element->appendElement( $node )

$element->appendNode( $node )

  Adds the new child to the end of this elements children list.

$element->cloneNode( $deep )

$element->cloneElement( $deep )

  Clones the current element, deep allows all child elements to be cloned.
  The new element is an orphan with all the same id's and atributes as this element.

$element->findChildIndex( $child )

  Scans through children trying to find this child in the list.

$element->insertAtIndex( $node, $index )

  Adds the new child at the specified index to this element.

$element->removeChildAtIndex( $index )

  Removed the child at index and returns the now orphaned element.

$element->createChildElement( $name, %options )

$element->createElement( $name, %options )

Not DOM2, creates a child element, appending to current element.

The advantage to using this method is the elements created with $document->createElement create basic element objects or base objects (those specified in the XML base class or it's kin) Elements created with this could offer more complex objects back.

Example: an SVG Gradiant will have stop elements under it, creating stop elements with $document->createElement will return an XML::DOM2::Element create a stop element with $element->createChildElement and it will return an SVG2::Element::Gradiant::Stop object (although both would output the same xml) and it would also prevent you from creating invalid child elements such as a group within a text element.

$element->createChildElement($name, %opts);


Martin Owens,


perl(1), XML::DOM2, XML::DOM2::Element DOM at the W3C

syntax highlighting: