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

getFirstChild

$child = $element->getFirstChild;

Returns the elements first child in it's children list

getLastChild

$child = $element->getLastChild;

Returns the elements last child in it's children list

getChildIndex

$index = $child->getChildIndex;

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

getChildAtIndex

$child = $element->getChildAtIndex($index);

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

getNextSibling

$sibling = $element->getNextSibling;

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

getPreviousSibling

$sibling = $element->getPreviousSibling;

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

getChildren

@children = $element->getChildren;

Returns all the elements children.

getChildrenByName

@children = $element->getChildrenByName;

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

hasChildren

$bool = $element->hasChildren;

Returns 1 if this element has children.

getParent / getParentElement

$parent = $element->getParent;

Returns the object of the parent element.

setParent / setParentElement

$element->setParent($parent);

Sets the parent node, used internaly.

getParents / getParentElements

@parents = $element->getParents;

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.

isAncestor

$bool = $element->isAncestor($descendant);

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

isDescendant

$bool = $element->isDescendant($ancestor);

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

@siblings = $element->getSiblings;

Returns a list of sibling elements.

hasSiblings

$bool = $element->hasSiblings;

Returns true if the elements has sibling elements.

getElementName

$name = $element->getElementName;

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

getElementID

$name = $element->getElementID;

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

getAttribute

$attribute = $element->getAttribute($attributeName, $ns, $serialise);

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

getAttributes

@attributes = $element->getAttributes( [$serialise] );

Returns a list of attributes in various forms.

getAttributeNames

@attributes = $element->getAttributeNames( $ns );

Returns a list of attribute names, used internaly.

hasAttribute

$bool = $element->hasAttribute($attribute);

Returns true ifthis element as this attribute.

hasAttributeNS

$bool = $element->hasAttributeNS($ns, $attribute);

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

hasAttributes

$bool = $element->hasAttributes();

Return true is element has any attributes

setAttribute

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

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

removeAttribute

$element->removeAttribute( $attribute );

Remove a single attribute from this element.

getAttributeNS

$namespace = $element->getAttributeNS( $attribute );

Returns an attributes namespace in this element.

setAttributeNS

$element->setAttributeNS( $uri, $name, $value );

Sets an attributes namespace in this element.

cdata

$string = $element->cdata; $element->cdata = $string; # overloaded to allow this

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

hasCDATA

$bool = $element->hasCDATA;

Return true if this element has cdata.

document

$document = $element->document;

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

insertBefore

$element->insertBefore($child, $refOtherChild);

Inserts a new child element just before the referenced child.

insertAfter

$element->insertAfter($child, $refOtherChild);

Inserts a new child element just after the referenced child.

insertSiblingAfter

$element->insertSiblingAfter($child);

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

insertSiblingBefore

$element->insertSiblingBefore($child);

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

replaceChild

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

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

replaceChild

$element->replaceElement($newElement);

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

removeChild

$oldChild = $element->removeChild($oldChild);

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

removeElement

$element->removeElement;

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

appendChild

$element->appendChild($newChild);

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

cloneNode

$newNode = $element->cloneNode($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.

findChildIndex

$index = $element->findChildIndex($Child);

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

insertAtIndex

$element->insertAtIndex($newChild, $index);

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

removeAtIndex

$element->removeAtIndex($index);

Removed the child at index and returns the now orphaned 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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 293:

Unknown directive: =head