The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

DESCRIPTION

Provides all the DOM method for XML Elements

METHODS

$element->getFirstChild() =head2 $element->firstChild()

  Returns the elements first child in it's children list

$element->getLastChild() =head2 $element->lastChild()

  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).

$element->getNextSibling() =head2 $element->nextSibling()

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

$element->getPreviousSibling() =head2 $element->previousSibling()

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

$element->getChildren() =head2 $element->getChildElements() =head2 $element->getChildNodes()

  Returns all the elements children.

$element->getChildrenByName( $name )

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

$element->hasChildren() =head2 $element->hasChildElements() =head2 $element->hasChildNodes()

  Returns 1 if this element has children.

$element->getParent() =head2 $element->getParentElement() =head2 $element->getParentNode()

  Returns the object of the parent element.

$element->setParent( $element ) =head2 $element->setParentElement( $element )

$element->setParent($parent);

Sets the parent node, used internaly.

$element->getParents() =head2 $element->getParentElements() =head2 $element->getParentNodes() =head2 $element->getAncestors()

  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.

$element->getSiblings()

  Returns a list of sibling elements.

$element->hasSiblings()

  Returns true if the elements has sibling elements.

$element->getElementName() =head2 $element->getElementType() =head2 $element->getType() =head2 $element->getTagName() =head2 $element->getTagType() =head2 $element->getNodeName() =head2 $element->getNodeType()

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

$element->getElementId()

  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.

$element->getAttributeNames()

  Returns a list of attribute names, used internaly.

$element->getAttributeNamesNS( $namespace )

  Returns a list of attribute names, used internaly.

$element->getAttributeNamespaces()

  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.

$element->hasAttributes()

  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)

$element->hasCDATA()

  Return true if this element has cdata.

$element->document()

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

$element->insertBefore( $node, $childNode ) =head2 $element->insertChildBefore( $node, $childNode ) =head2 $element->insertNodeBefore( $node, $childNode ) =head2 $element->insertElementBefore( $node, $childNode )

  Inserts a new element just before the referenced child.

$element->insertAfter( $node, $childNode ) =head2 $element->insertChildAfter( $node, $childNode ) =head2 $element->insertElementAfter( $node, $childNode ) =head2 $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 ) =head2 $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.

$element->removeElement() =head2 $element->removeNode()

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

$element->appendChild( $node ) =head2 $element->appendElement( $node ) =head2 $element->appendNode( $node )

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

$element->cloneNode( $deep ) =head2 $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

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 t would also prevent you from creating invalid child elements such as a group within a text element.

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

AUTHOR

Martin Owens, doctormo@postmaster.co.uk

SEE ALSO

perl(1), XML::DOM2, XML::DOM2::Element

http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html DOM at the W3C