NAME
HTML::DOM::Attr - A Perl class for representing attribute nodes in an HTML DOM tree
VERSION
Version 0.055
SYNOPSIS
use HTML::DOM;
$doc = HTML::DOM->new;
$attr = $doc->createAttribute('href');
$attr->nodeValue('http://localhost/');
$elem = $doc->createElement('a');
$elem->setAttributeNode($attr);
$attr->nodeName; # href
$attr->nodeValue; # http://...
$attr->firstChild; # a text node
$attr->ownerElement; # returns $elem
DESCRIPTION
This class is used for attribute nodes in an HTML::DOM tree. It implements the Node and Attr DOM interfaces and inherits from HTML::DOM::EventTarget. An attribute node stringifies to its value. As a boolean it is true, even if its value is false.
METHODS
Attributes
The following DOM attributes are supported:
- nodeName
- name
-
These both return the name of the attribute.
- nodeType
-
Returns the constant
HTML::DOM::Node::ATTRIBUTE_NODE
. - nodeValue
- value
-
These both return the attribute's value, setting it if there is an argument.
- specified
-
Returns true if the attribute was specified explicitly in the source code or was explicitly added to the tree.
- parentNode
- previousSibling
- nextSibling
- attributes
- namespaceURI
- prefix
- localName
-
All of these simply return an empty list.
- childNodes
-
In scalar context, this returns a node list object with one text node in it. In list context it returns a list containing just that text node.
- firstChild
- lastChild
-
These both return the attribute's text node.
- ownerDocument
-
Returns the document to which the attribute node belongs.
- ownerElement
-
Returns the element to which the attribute belongs.
Other Methods
- insertBefore
- removeChild
- appendChild
-
These three just throw exceptions.
- replaceChild
-
If the first argument is a text node and the second is the attribute node's own text node, then the latter is replaced with the former. This throws an exception otherwise.
- hasChildNodes
-
Returns true.
- cloneNode
-
Returns a clone of the attribute.
- normalize
-
Does nothing.
- hasAttributes
-
Returns false.
- isSupported
-
Does the same thing as HTML::DOM::Implementation's hasFeature method.