HTML::DOM::Attr - A Perl class for representing attribute nodes in an HTML DOM tree
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
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.
The following DOM attributes are supported:
These both return the name of the attribute.
Returns the constant HTML::DOM::Node::ATTRIBUTE_NODE.
HTML::DOM::Node::ATTRIBUTE_NODE
These both return the attribute's value, setting it if there is an argument.
Returns true if the attribute was specified explicitly in the source code or was explicitly added to the tree.
All of these simply return an empty list.
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.
These both return the attribute's text node.
Returns the document to which the attribute node belongs.
Returns the element to which the attribute belongs.
These three just throw exceptions.
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.
Returns true.
Returns a clone of the attribute.
Does nothing.
Returns false.
Does the same thing as HTML::DOM::Implementation's hasFeature method.
HTML::DOM
HTML::DOM::Node
HTML::DOM::Element
HTML::DOM::EventTarget
To install HTML::DOM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::DOM
CPAN shell
perl -MCPAN -e shell install HTML::DOM
For more information on module installation, please visit the detailed CPAN module installation guide.