NAME

Mozilla::DOM::Node

DESCRIPTION

Mozilla::DOM::Node is a wrapper around an instance of Mozilla's nsIDOMNode interface. This class inherits from Supports.

 * The nsIDOMNode interface is the primary datatype for the entire
 * Document Object Model.
 * It represents a single node in the document tree.
 *
 * For more information on this interface please see
 * L<http:E<sol>E<sol>www.w3.orgE<sol>TRE<sol>DOM-Level-2-CoreE<sol>>

CLASS METHODS

$iid = Mozilla::DOM::Node->GetIID()

Pass this to QueryInterface.

ATTRIBUTES

$namednodemap = $node->GetAttributes()

A Mozilla::DOM::NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

In list context, returns a list of Mozilla::DOM::Attr, instead. (I considered returning a hash ($attr->GetName => $attr->GetValue), but then you couldn't set the attributes.)

$bool = $node->HasAttributes()

Returns whether this node (if it is an element) has any attributes.

$nodelist = $node->GetChildNodes()

A Mozilla::DOM::NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.

In list context, this returns a list of Mozilla::DOM::Node, instead.

$bool = $node->HasChildNodes()

This is a convenience method to allow easy determination of whether a node has any children.

$node = $node->GetFirstChild()

The first child of this node. If there is no such node, this returns null.

node = $node->GetLastChild

The last child of this node. If there is no such node, this returns null.

$node = $node->GetPreviousSibling()

The node immediately preceding this node. If there is no such node, this returns null.

$node = $node->GetNextSibling()

The node immediately following this node. If there is no such node, this returns null.

$name = $node->GetNodeName()

The name of this node, depending on its type:

Attr

The name of the attribute

CDATASection

#cdata-section

Comment

#comment

Document

#document

DocumentFragment

#document-fragment

DocumentType

The document type name

Element

The tag name

Entity

The entity name

EntityReference

The name of the entity referenced

Notation

The name of the notation

ProcessingInstruction

The target

Text

#text

$type = $node->GetNodeType()

Matches one of the following constants, which you can export with use Mozilla::DOM::Node qw(:types), or export them individually.

ATTRIBUTE_NODE

The node is a Mozilla::DOM::Attr.

CDATA_SECTION_NODE

The node is a Mozilla::DOM::CDATASection.

COMMENT_NODE

The node is a Mozilla::DOM::Comment.

DOCUMENT_NODE

The node is a Mozilla::DOM::Document.

DOCUMENT_TYPE_NODE

The node is a Mozilla::DOM::DocumentType.

DOCUMENT_FRAGMENT_NODE

The node is a Mozilla::DOM::DocumentFragment.

ELEMENT_NODE

The node is a Mozilla::DOM::Element.

ENTITY_REFERENCE_NODE

The node is a Mozilla::DOM::EntityReference.

ENTITY_NODE

The node is a Mozilla::DOM::Entity.

NOTATION_NODE

The node is a Mozilla::DOM::Notation.

PROCESSING_INSTRUCTION_NODE

The node is a Mozilla::DOM::ProcessingInstruction.

TEXT_NODE

The node is a Mozilla::DOM::Text.

$value = $node->GetNodeValue()

The value of this node, depending on its type:

Attr

The value of the attribute

CDATASection

The content of the CDATA section

Comment

The content of the comment

Document

[null]

DocumentFragment

[null]

DocumentType

[null]

Element

[null]

Entity

[null]

EntityReference

[null]

Notation

[null]

ProcessingInstruction

The entire content excluding the target

Text

The content of the text node

$node->SetNodeValue($value)

    • $value (string)

$document = $node->GetOwnerDocument()

The Mozilla::DOM::Document object associated with this node. This is also the Document object used to create new nodes. When this node is a Document or a DocumentType which is not used with any Document yet, this is null.

$node = $node->GetParentNode()

The parent of this node. All nodes, except Attr, Document, DocumentFragment, Entity, and Notation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.

$name = $node->GetLocalName()

Returns the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

$uri = $node->GetNamespaceURI()

The namespace URI of this node, or null if it is unspecified. This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.

For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

$prefix = $node->GetPrefix()

The namespace prefix of this node, or null if it is unspecified.

For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

$node->SetPrefix($prefix)

Note that setting this attribute, when permitted, changes the nodeName attribute, which holds the qualified name, as well as the tagName and name attributes of the Element and Attr interfaces, when applicable.

Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since the namespaceURI and localName do not change.

    • $aPrefix (string)

$bool = $node->IsSupported($feature, $version)

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

    • $feature (string)

      The name of the feature to test. This is the same name which can be passed to the method hasFeature on DOMImplementation.

    • $version (string)

      This is the version number of the feature to test. In Level 2, version 1, this is the string "2.0". If the version is not specified, supporting any version of the feature will cause the method to return true.

    two string args

METHODS

$node = $node->AppendChild($newChildNode)

Adds the node newChildNode to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

    • $newChild (Mozilla::DOM::Node)

      The node to add. If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node.

$node = $node->CloneNode($deep)

Returns a duplicate of this node. (See DOM 1 spec for details.)

    • $deep (boolean)

      If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).

    DOM 2 spec: When a Node is copied using the cloneNode method the EventListeners attached to the source Node are not attached to the copied Node. If the user wishes the same EventListeners to be added to the newly created copy the user must add them manually.

$node = $node->InsertBefore($newChildNode, $refChildNode)

Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children.

If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If the newChild is already in the tree, it is first removed.

    • $newChild (Mozilla::DOM::Node)

      The node to insert.

    • $refChild (Mozilla::DOM::Node)

      The reference node, i.e., the node before which the new node must be inserted.

$node = $node->RemoveChild($oldChildNode)

Removes the child node indicated by oldChild from the list of children, and returns it.

    • $oldChild (Mozilla::DOM::Node)

$node = $node->ReplaceChild($newChildNode, $oldChildNode)

Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.

If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.

    • $newChild (Mozilla::DOM::Node)

      The new node to put in the child list.

    • $oldChild (Mozilla::DOM::Node)

      The node being replaced in the list.

$node->Normalize()

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.

See DOM 2 spec for details.

SEE ALSO

Mozilla::DOM

COPYRIGHT

Copyright (C) 2005-2007, Scott Lanning

This software is licensed under the LGPL. See Mozilla::DOM for a full notice.