Anda di halaman 1dari 1

3236-7 ch04.F.

qc

6/29/99

1:04 PM

Page 65

Chapter 4 Structuring Data

Note

Readers familiar with database theory may recognize XMLs model as essentially a
hierarchical database, and consequently recognize that it shares all the disadvantages (and a few advantages) of that data model. There are certainly times when a
table-based relational approach makes more sense. This example certainly looks
like one of those times. However, XML doesnt follow a relational model.
On the other hand, it is completely possible to store the actual data in multiple
tables in a relational database, then generate the XML on the fly. Indeed, the larger
examples on the CD-ROM were created in that fashion. This enables one set of
data to be presented in multiple formats. Transforming the data with style sheets
provides still more possible views of the data.

Since my personal interests lie in analyzing player performance within a single


season, Im going to make season the root of my documents. Each season will
contain leagues, which will contain divisions, which will contain players. Im
not going to granularize my data all the way down to the level of individual
games, innings, or plays because while useful such examples would be
excessively long.
You, however, may have other interests. If you choose to divide the data in some
other fashion, that works too. Theres almost always more than one way to organize
data in XML. In fact, well return to this example in several upcoming chapters
where well explore alternative markup vocabularies.

XMLizing the Data


Lets begin the process of marking up the data for the 1998 Major League season in
XML with tags that you define. Remember that in XML were allowed to make up the
tags as we go along. Weve already decided that the fundamental element of our
document will be a season. Seasons will contain leagues. Leagues will contain
divisions. Divisions will contain teams. Teams contain players. Players will have
statistics including games played, at bats, runs, hits, doubles, triples, home runs,
runs batted in, walks, and hits by pitch.

Starting the Document: XML Declaration


and Root Element
XML documents may be recognized by the XML declaration. This is a processing
instruction placed at the start of all XML files that identifies the version in use. The
only version currently understood is 1.0.
<?xml version=1.0?>

Every good XML document (where the word good has a very specific meaning to be
discussed in the next chapter) must have a root element. This is an element that
completely contains all other elements of the document. The root elements start

65

Anda mungkin juga menyukai