- 115 -
Figure 5.1:
Alert box.
For those completely new to programming, especially with JavaScript, a primer might be
necessary. Briefly, a property is a variable that is attached to the object and is usually a
string, an integer, or another node object like a NodeList. For example, the nodeName
property on nodes is a string that represents the name of a node. On the other hand, a
method performs some sort of action and usually has parameters and a return value. For
example, the method called insertBefore(...) is used to place nodes into the tree. Methods
and properties can be accessed from the main object by using a period.
someNode.nodeName produces the nodeName property of the someNode node. Objects
can also be cascaded in this fashion. For example, someNode
.
childNodes.length
produces the length property found on the childNodes property, where childNodes is a
property of someNode. someNode.childNodes.length is a shortcut for assigning
childNodes to a variable and then using it.
Enough about JavaScript. The examples in this section are quite straightforward,
because only one property or method is displayed at a time. The more involved scenarios
in later chapters bring the various concepts together in one place.
Some basic knowledge of the DOM is also needed to understand the examples. The
chapter is organized in a reference style for easy access while programming. For the
first-time reader, a few methods and properties need to be briefly explained to
understand the examples. The documentElement property found on the Document node
points to the top most XML element. Looking at the following the XML data island, root is
the top most element; therefore documentElement is the root Element node.