- 103 -
Figure 4.3:
Actual model of a tree using a NodeList.
NamedNodeMap.
This
node is similar to NodeList, but possesses additional
functionality for accessing child nodes using their name. This functionality is necessary
for
accessing attributes; as a result, NamedNodeMap nodes are used to hold attribute
nodes.
Element.
The Element node type (see Figure 4.4) contains an
element from an XML
document. It has special facilities, which are described in
Chapter 5
,
for accessing and
managing the attributes declared within the element. Element nodes are children of other
element nodes, except for the topmost element node, which
is a child of the document
node. This topmost element node is referred to as the documentElement. The following
XML document would have two Element nodes: root and someElement. The root
Element node would be
a child of the Document node, and the someElement Element
node would be a child of the root Element node.
Figure 4.4:
Tree model of Element example.
Text.
Text nodes are used to represent the text that is contained within element tags
(see Figure 4.6). The following XML document produces a Text
node that is a child of the
name Element node. This text node contains the value “Alex.”
- 104 -
Alex
Figure 4.6:
Tree model of Text example.
Attr (Attribute).
The Attr node type represents the attributes that are declared within the
scope of an element (see Figure 4.7). Attribute nodes can also be children of nodes other
than
Element nodes, such as Entity and Notation nodes. The following XML document
produces an Element node for root and an Attribute node for myAttribute. The
myAttribute Attribute node is a child of the root Element node. A NamedNodeMap
collection is used instead of the NodeList collection to hold attributes. Also,
a Text node
representing someValue is exposed.