Refresher: Object-oriented programming; e.g. JavaScript
December 21, 1998
We're focusing on
JavaScript
because it is a relatively
simple language with deeply traditional roots: anyone
familiar with variables, loops, conditions and so forth
can quickly adapt to the JavaScript paradigm. Into this
mix JavaScript introduces the concept of objects,
essentially container constructs which possess any number
of associated values known as properties and procedures
(a.k.a. "functions") known as methods.
In processing XML data via the Document Object Model we can
think of JavaScript as a nearly generic object-oriented
language. It should be easy to translate these concepts into
the syntax of other languages such as VBScript or
even C++, if you are familiar with those rather than JavaScript,
per se.
Language aside, the syntax we use to access the
XML
document is
mostly defined by the
Document Object Model,
itself, rather than the particular programming language. In
this sense, an understanding of the DOM will aid in
understanding the examples in this article moreso than a
mastery of a particular language. To best understand the
role of the Document Object Model, and why it's reflection
of the XML tree is important, see
"The DOM Dissected."
In processing XML we will be concerned mostly with objects
representing components of the XML tree. In thinking
of the XML data itself we can employ the metaphor of a
tree -- an arboreal tree, as opposed to a family tree, which
is another metaphor we will encounter later. We can imagine
there will be an object analogous to the trunk, an
object representing a branch (a.k.a. "node"),
and an object representing a leaf. Generally speaking,
then, we would use the following generic syntax to access
the second leaf of the first branch:
Leaf Object:
trunk.branch(0).leaf
valueProperty of Leaf Object:
trunk.branch(0).leaf.valueProperty
Thus, we could assign a new value to the above leaf:
trunk.branch(0).leaf.valueProperty="red"
Remember, these are not syntactically accurate examples, simply
conceptual sketches to illustrate the object-oriented
nature of the XML tree. That said, let's consider just what
XML and this "tree" are after all ...
XML via the Document Object Model: A Preliminary Course
XML via the Document Object Model: A Preliminary Course
Refresher: XML
|