XML Objectified: IDOMElement
December 21, 1998
Now that we have some practice with references and know
how to determine the type of node, let's focus on the
IDOMElement node and begin climbing the XML tree. The
trunk itself -- the root XML element node, is the IDOMElement
child of the IDOMDocument object. Now that we're focused on
the XML tree, and specifically the
"trunk",
we return to the arboreal tree metaphor.
Recall that the trunk of our pets.xml tree is the element
<petfolio>. We can verify this
via the nodeName property of the IDOMElement object:
|
petbase.childNodes(1).nodeName |
yields
|
"petfolio" |
As the trunk of our XML tree, petfolio
leads to two branches, each one being a <pet>
element. Therefore, if we want to examine or modify an existing
branch of this tree, we will have to climb a bit
further into one of these pet nodes. Using
the length property of the childNodes list
our program can determine that two branches are connected
to the trunk:
|
petbase.childNodes(1).childNodes.length |
yields
|
2 |
Two branches, although we don't know that both branches
are necessarily pet nodes (though they
are in this example). This is easy enough to verify, however:
|
petbase.childNodes(1).childNodes(0).nodeName |
yields
|
"pet" |
|
petbase.childNodes(1).childNodes(1).nodeName |
yields |
"pet" |
Understandably, these reference syntaxes are growing
rather intimidating, as we climb higher and higher into
the XML tree. Most real-world programs will rely on
shortcuts to these references, but we write them out explicitly
here so you can best follow along.
XML Objectified: IDOMNode's
XML via the Document Object Model: A Preliminary Course
XML Objectified: Attributes Considered
|