The manakai project

Web::DOM::Node

DOM Node object

DESCRIPTION

The Web::DOM::Node class implements the DOM Node interface. The Web::DOM::Node class is an abstract class. It is used as subclasses such as Web::DOM::Element and Web::DOM::Document.

METHODS

In addition to the methods of the Web::DOM::EventTarget class, following methods are available:

$child = $node->append_child ($child)

Append the specified node to the list of child nodes. [DOM]

$node->manakai_append_content ($child)

Append the specified node or string. If the context object is an HTML template element, it is appended to the template content. Otherwise, it is appended to the context object. [MANAKAI]

$node = $node->manakai_append_text ($string)

Append a string to the text_content of the node. [MANAKAI]

$node->manakai_append_indexed_string ($indexed)

Append an IndexedString <http://wiki.suikawiki.org/n/manakai%20index%20data%20structures#anchor-1> to the text_content of the node. [MANAKAIINDEX]

$string = $node->base_uri

Return the base URL of the node. [DOM] [HTML] [DOMDTDEF]

See also "DEPENDENCY" in Web::DOM.

$node_list = $node->child_nodes

Return the live list, i.e. Web::DOM::NodeList, of the child nodes of the node. [DOM]

$node2 = $node->clone_node ($deep)

Return the newly-created clone of the node. If the argument is set to the true value, any descendant nodes are also cloned. [DOM] [DOMATTREXODUS] [DOMDTDEF] [HTML] [MANAKAI]

$value = $node1->compare_document_position ($node2)

Return the result of comparison of document positions of two nodes. The result is represented as the bitmask of constants listed in the later section. [DOM] [DOM3CORE]

$bool = $node1->contains ($node2)

Return whether the node specified as the argument is the descendant of the context node or not. [DOM]

$url = $node->manakai_expanded_uri

Return the expanded URL of the element or attribute, i.e. the namespace URL followed by the local name. [MANAKAI]

$child = $node->first_child

Return the first child node of the node. If there is no child, undef is returned. [DOM]

$url = $node->manakai_get_child_namespace_uri ($name)

Return the namespace URL which would be used if the serialized representation of the node contains a start tag whose tag name is equal to the argument. [MANAKAI]

For example:

  $doc = an HTML document;
  $el = $doc->create_element ('div');
  is $el->manakai_get_child_namespace_uri ('p'),
     'http://www.w3.org/1999/xhtml';
  is $el->manakai_get_child_namespace_uri ('svg'),
     'http://www.w3.org/2000/svg';
$indexed = $node->manakai_get_indexed_string

Return an IndexedString <http://wiki.suikawiki.org/n/manakai%20index%20data%20structures#anchor-1> representation of the text_content of the node. [MANAKAIINDEX]

['', $di, $ci] = $node->manakai_get_source_location

Return an array reference containing document and character index values, which might be able to use to find the location in the source text from which the node is created, if any. If they are not known, an array reference ['', -1, 0] is returned instead. The first (zeroth) item is always the empty string. [MANAKAIINDEX]

$data = $node->get_user_data ($key)

Return the user data associated to the node with the specified key, if any, or undef. [DOM3CORE]

See "USER DATA".

$bool = $node->has_child_nodes

Return whether the node has children or not. [DOM]

$child = $node->insert_before ($child, $ref_child)

Insert the specified node just after the specified node. [DOM]

$bool = $node->is_default_namespace ($nsurl)

Return whether the specified namespace URL is the default namespace or not. [DOM]

$bool = $node1->is_equal_node ($node2)

Return whether two nodes are equal or not. [DOM] [DOMATTREXODUS] [MANAKAI]

$bool = $node1->is_same_node ($node2)

Return whether two nodes are same or not. [DOM]

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

Return true. [MANAKAI]

$child = $node->last_child

Return the last child node of the node. If there is no child, undef is returned. [DOM]

$url = $node->lookup_namespace_uri ($prefix)

Return the namespace URL which might be associated with the specified prefix. The undef value can be specified for the default namespace. [DOM] [DOMATTREXODUS] [DOM3CORE]

$prefix = $node->lookup_prefix ($nsurl)

Return the namespace prefix which might be associated with the specified namespace URL. [DOM] [DOMATTREXODUS] [DOM3CORE]

$sibling = $node->next_sibling

Return the next sibing node of the node. If there is no such node, undef is returned. [DOM] [DOMATTREXODUS]

$string = $node->node_name

Return the name of the node. [DOM] [DOMATTREXODUS] [DOMDTDEF]

$number = $node->node_type

Return the constant number representing the type of the node. [DOM] [DOMATTREXODUS] [DOMDTDEF]

$text = $node->node_value
$node->node_value ($text)

Get or set the value of the node. For Web::DOM::CharacterData objects, this is equivalent to the data method. For Web::DOM::Attr objects, this is equivalent to the value method. For other kinds of nodes, this method has no effect. [DOM] [DOMATTREXODUS]

$node->normalize

Normalize descendant contigious Text nodes, if any. [DOM]

$doc = $node->owner_document

Return the node document, i.e. the document the node belongs to, except for the document node, fot which the undef value is returned. [DOM]

$parent = $node->parent_element
$parent = $node->manakai_parent_element

Return the parent element of the node. If there is no parent element, undef is returned. [DOM] [MANAKAI]

$parent = $node->parent_node

Return the parent node of the node. If there is no parent, undef is returned. [DOM] [DOMATTREXODUS]

$sibling = $node->previous_sibling

Return the previous sibling of the node. If there is no such node, undef is returned. [DOM] [DOMATTREXODUS]

$old_child = $node->remove_child ($old_child)

Remove a node from the list of child nodes of the node. [DOM]

$new_child = $node->replace_child ($new_child, $ref_child)

Replace the specified child node by a new node. The first argument is the new child node. The second argument is the current child node, which is to be replaced. The new child node is returned. [DOM]

$node->manakai_set_source_location (['', $di, $ci])

Set an array reference containing document and character index values, which might be able to use to find the location in the source text from which the node is created. The first (zeroth) item in the array reference is ignored. If the node is not associated with any source text (e.g. created by a DOM method), or the actual source location is known, values -1 and 0 should be used. [MANAKAIINDEX]

$node->set_user_data ($key, $value, $handler)

Set the specified key-value pair as one of user data of the node. [DOM3CORE]

Note that this implementation does not support user data handler. The third argument cannot be specified.

See "USER DATA".

$string = $node->text_content
$node->text_content ($string)

Return or set the text data of the node. [DOM] [DOMATTREXODUS] [MANAKAI]

If the node is an Element or DocumentFragment, setter: The content of the node is replaced by a new Text node if the new text data is not the empty string. If the node has child nodes, they are removed.

If the node is a CharacterData or Attr: The data of the node is returned or replaced.

Otherwise, the method returns undef and the setter has no effect.

Following methods are also available: attributes, has_attributes, prefix, namespace_uri, local_name, and manakai_local_name. [DOMNODEEXODUS] [MANAKAI]

Any Node object is an instance of one of its subclasses. For example, a Node object whose node_type is ELEMENT_NODE is an instance of Web::DOM::Element. There are following subclasses:

Web::DOM::Element, Web::DOM::Document, Web::DOM::DocumentType, Web::DOM::DocumentFragment, Web::DOM::CharacterData, Web::DOM::Attr, Web::DOM::Entity, Web::DOM::Notation, Web::DOM::ElementTypeDefinition, and Web::DOM::AttributeDefinition.

CONSTANTS

Constants are exported from the Web::DOM::Node module by default. In addition, they are accessible as methods of Node objects.

Node type constants

Following constants are defined for the node_type attribute:

ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE [DOM] [DOMATTREXODUS] [DOM3]

XPATH_NAMESPACE_NODE [DOMXPATH]

ELEMENT_TYPE_DEFINITION_NODE ATTRIBUTE_DEFINITION_NODE [DOMDTDEF]

Document position constants

Following constants are defined for the compare_document_position method:

DOCUMENT_POSITION_DISCONNECTED DOCUMENT_POSITION_PRECEDING DOCUMENT_POSITION_FOLLOWING DOCUMENT_POSITION_CONTAINS DOCUMENT_POSITION_CONTAINED_BY DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC [DOM]

USER DATA

Methods get_user_data and set_user_data can be used to store and retrieve custom data associated with the node.

Please note that, if the value directly or indirectly references the node itself, the node will not be garbage collected even when the other references to the node have been removed. This is the limitation of the Perl's garbage collection mechanism.

User data keys with prefix manakai_ are used by various Perl modules by the manakai project. Other modules and applications should not use such keys. See <http://suika.suikawiki.org/~wakaba/wiki/sw/n/manakai++Predefined%20User%20Data%20Names> for the list of currently used keys.

SPECIFICATIONS

DOM

DOM Living Standard <http://dom.spec.whatwg.org/#interface-document>.

DOMATTREXODUS, DOMNODEEXODUS

DOM Standard <view-source:http://dom.spec.whatwg.org/>.

HTML

HTML Standard <http://www.whatwg.org/specs/web-apps/current-work/>.

DOM3CORE

Document Object Model (DOM) Level 3 Core Specification <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/DOM3-Core.html#core-ID-1950641247>.

DOMXPATH

Document Object Model XPath <http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html>.

DOMDTDEF

DOM Document Type Definition Module <http://suika.suikawiki.org/www/markup/xml/domdtdef/domdtdef-work>.

MANAKAI

manakai DOM Extensions <http://suika.suikawiki.org/~wakaba/wiki/sw/n/manakai%20DOM%20Extensions>.

MANAKAIINDEX

manakai index data structures <http://wiki.suikawiki.org/n/manakai%20index%20data%20structures>.

SEE ALSO

Web::DOM::NodeList, Web::DOM::HTMLCollection, Web::DOM::NamedNodeMap.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2012-2016 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.