- 102 -
Visual Basic. The diagrams presented in the next section can be easily verified by
copying the XML snippets into a file and then loading them in with the DOMifier.
Changing a few lines around and reloading can help you get a feel for what the DOM
exposes much faster than just reading alone. Figure 4.5
shows an example of the
DOMifier output.
Figure 4.5:
DOMifier display of
Figure 4.4
.
Different Node Types
A brief description of each node type is given below, and an in-depth
look at each node is
provided in later chapters.
Each of the following node types is derived from a base class called Node. A developer
never creates a generic node, but rather creates one of the following nodes to model the
appropriate behavior of a fragment of an XML document.
Each of these nodes can
identify themselves through the nodeType property. A numerical value is assigned to
every node, and the nodeType returns the numerical value associated to a particular
node. Details about the nodeType property are described in
Chapter 5
.
Document.
The Document
node is the master node; only one of these nodes can exist
for an XML document. This node is the top-most parent node and represents the XML
document as a whole. In other words, the document node doesn’t
represent any specific
piece of the XML document. This node has the special functionality to create other
nodes, which can then be inserted into the tree.
NodeList.
A NodeList node is used to hold a collection of child nodes. This node can
also tell the parent how many children are present, a feature that is useful in loops. Not
all
nodes can have children; that is, not all nodes can have a NodeList collection.
Conceptually, the NodeList is just a facility to gain access to the children of a given node.
Figure 4.2 shows a simple tree: a parent and three children. Figure 4.3 shows how a
NodeList node is like any other node in a model, but is used only to group the children.
This NodeList facility provides a uniform mechanism for accessing child nodes.