A Tree Grows in XML
December 21, 1998
XML data is highly structured in a tree form. This is
vitally important because knowing this allows us to traverse
this tree programmatically without needing to know the
exact configuration of the tree (how many branches does
it have, etc.) and without even needing to know the type
of data contained within.
Let's look at the petfolio XML document grown as a tree.

Artistic skills aside, the above tree serves to
represent the structure of the data within the petfolio XML
document. We can also see that certain rules preside over
this structure: a branch extends from the trunk, smaller
branches extend from a larger branch, and leaves extend
from these smaller branches; yet, a leaf cannot extend
directly from the trunk. Similarly, a branch cannot extend
from a leaf -- leaves are terminal nodes, then. A branch,
however, can certainly extend from another branch.
Taken together, the rules outlined above describe a
hierarchy-based ruleset. Your XML ruleset may be far more
complicated, but ultimately you will have leaves which
serve as terminal nodes, which hold the meat of your data.
In the lingo of programmers, the terms "parent"
and "child" are used to describe the relationships
between nodes, veering away from the arboreal tree analogy
and towards a family tree analogy. The translation is
simple, though: a branch is a child of the trunk and a parent
to a leaf. A leaf is a child to a branch and a parent
to no one. That last point will be important later -- terminal
nodes (a.k.a. "a leaf") cannot be parents.
Aside from that, most XML elements can serve as either and
both parents and children, just as in living extended
families.
Refresher: XML
XML via the Document Object Model: A Preliminary Course
"Exploring" the Tree
|