NAME
HTML::DOM::Node - A Perl class for representing the nodes of an HTML DOM tree
SYNOPSIS
use HTML::DOM::Node ':all'; # constants
use HTML::DOM;
$doc = HTML::DOM->new;
$doc->isa('HTML::DOM::Node'); # true
$doc->nodeType == DOCUMENT_NODE; # true
$doc->firstChild;
$doc->childNodes;
# etc
DESCRIPTION
This is the base class for all nodes in an HTML::DOM tree. (See "CLASSES AND DOM INTERFACES" in HTML::DOM.) It implements the Node and EventTarget DOM interfaces.
METHODS
Attributes
The following DOM attributes are supported:
- nodeName
- nodeType
-
These two are implemented not by HTML::DOM::Node itself, but by its subclasses.
- nodeValue
- parentNode
- childNodes
- firstChild
- lastChild
- previousSibling
- nextSibling
- attributes
- ownerDocument
- namespaceURI
- prefix
- localName
-
Those last three always return nothing.
There is also a _set_ownerDocument
method, which you probably do not need to know about.
Other Methods
See the DOM spec. for descriptions of most of these.
- insertBefore
- replaceChild
- removeChild
- appendChild
- hasChildNodes
- cloneNode
- normalize
- hasAttributes
- isSupported
- addEventListener($event_name, $listener, $capture)
-
The
$listener
should be either a coderef or an object with ahandleEvent
method. (HTML::DOM does not implement any such object since it would just be a wrapper around a coderef anyway, but has support for them.) An object with&{}
overloading will also do.$capture
is a boolean indicating whether this is to be triggered during the 'capture' phase. - removeEventListener($event_name, $listener, $capture)
-
The
$listener
should be the same reference passed toaddEventListener
. - get_event_listeners($event_name, $capture)
-
This is not a DOM method (hence the underscores in the name). It returns a list of all event listeners for the given event name.
$capture
is a boolean that indicates which list to return, either 'capture' listeners or normal ones. - dispatchEvent($event_object)
-
$event_object is an object returned by HTML::DOM's
createEvent
method, or any object that implements the interface documented in HTML::DOM::Event.dispatchEvent
does not automatically call the handler passed to the document'sdefault_event_handler
. It is expected that the code that calls this method will do that (see also "trigger_event").The return value is a boolean indicating whether the default action should be taken (i.e., whether preventDefault was not called).
- trigger_event($event)
-
Here is another non-DOM method.
$event
can be an event object or simply an event name. This method triggers an event for real, first callingdispatchEvent
and then running the default action for the event unless an event listener cancels it. - as_text
- as_HTML
-
These two (non-DOM) methods of HTML::Element are overridden, so that they work correctly with comment and text nodes.
EXPORTS
The following node type constants are exportable:
- ELEMENT_NODE (1)
- ATTRIBUTE_NODE (2)
- TEXT_NODE (3)
- CDATA_SECTION_NODE (4)
- ENTITY_REFERENCE_NODE (5)
- ENTITY_NODE (6)
- PROCESSING_INSTRUCTION_NODE (7)
- COMMENT_NODE (8)
- DOCUMENT_NODE (9)
- DOCUMENT_TYPE_NODE (10)
- DOCUMENT_FRAGMENT_NODE (11)
- NOTATION_NODE (12)