Refresher: XML
December 21, 1998
XML
is a author-defined meta markup language with
which you create an internal structure for containing data,
quite similar to a database. XML has been touted as
a "replacement" for
HTML
but it extends far beyond
that -- XML is a data exchange format from which you
can manipulate data in any number of ways, from internal
processing to external display (the HTML connection).
An XML document is composed of data embedded within markup
tags,
quite reminiscent of an HTML document, but the
tags may be self-defined. These tags define the internal
structure of the embedded data, quite analogous to a database
containing records and fields, based upon rules set forth
in a separate document known as the
DTD, or Document Type Definition.
Simple XML files with straightforward
rulesets do not require an explicitly defined DTD. A very
easy way to understand the root concept of XML is to look
at a simple XML example, a file we've named "petfolio.xml":
<?xml version="1.0"?>
<petfolio>
<pet name="ella dibella">
<breed>Domestic Shorthair</breed>
<color>black/tan tiger</color>
<age units="months">3</age>
<weight units="lbs">1.75</weight>
<description>Ella is a smart, poised
creature full of courage and vinegar.
</description>
</pet>
<pet name="borders mcgee">
<breed>Domestic Shorthair</breed>
<color>black/white tuxedo</color>
<age units="weeks">10</age>
<weight units="lbs">1.5</weight>
<description>Borders is a playful,
submissive jester. </description>
</pet>
</petfolio>
|
The above XML document does not require an external DTD --
it's ruleset can be implied for the basic structure
of the document. The root object of this dataset is named
petfolio, and we can imagine that it represents
a portfolio of pets. Each pet in this portfolio is essentially
a record, if you are familiar with database lingo.
A pet "record" is bookended by <pet> tags.
One of the great powers of XML is that you
can define these tags at will, as long as the structure of
the data obeys rules set out in the DTD or which can
be implied simply from the XML document itself. One rule in
this document, for example, is that the <pet>
tag occurs within the <petfolio> tag, and all
other tags in the document reside within the <pet>
tags. In other words, we've created a database with records
which may contain fields.
The "fields" in this case are <breed>,
<color>, <age>, <weight>,
and <description>. Some of these tags possess
attributes, which contain values relevant to the processing
of that tag; for example, the <age> tag possess
a units attribute indicating the units in which
this tag's value ("10") is measured on. The same
can be observed for the <weight> tag, and
the <pet> tag itself, which assigns an identifier
to the record via the name attribute.
Visually speaking, the entire petfolio XML document can be
represented as a tree ... literally, that is, the
kind of tree which grows in your yard.
Refresher: Object-oriented programming; e.g. JavaScript
XML via the Document Object Model: A Preliminary Course
A Tree Grows in XML
|