- 125 -
The appendChild method automatically removed childElement2 from the child list of
elem2, before inserting it into the child list of elem1. Figures 5.7 and 5.8 shows the before
and after DOM representation of this XML document.
Figure 5.7:
DOM representation of original
XML document in appendChild
example.
Figure 5.8:
DOM representation of XML document after childElement2 is moved.
hasChildNodes()
Parameters
: None
Return value
: Boolean
Exceptions thrown
: None
Description
: This method returns
true
if this node has children and
false
otherwise.
cloneNode(deep)
Parameters
:
deep
is a Boolean value.
Return value
: Node
Exceptions thrown:
None
Description
: cloneNode is used to produce a copy of the node that it is called on. For
those familiar with object-oriented
programming terminology, this function fulfills the role
- 126 -
of a copy-constructor. If deep is false,
then the node is copied, but its children are
ignored. If deep is true, then a complete replica of the subtree starting
at the current node
is returned.
Comments
: Calling cloneNode(true) can result in a very processing-intensive operation,
especially if called on the Document node of a large document.
Document
Parent
: Node
The Document node is not an element; rather it represents the document as a whole. In
data islands,
the id attribute on the tag is a reference to the Document node.
The Document node is the root node that contains the facilities to manage the various
nodes beneath it. More specifically, the Document node is used to create nodes that can
later be inserted into the tree. Also included is a basic searching mechanism. In addition
to these facilities, the Document node contains pointers to other important nodes in the
tree, such as the root Element node and the DocumentType node.