Datasheet
The markup in XML documents consists of data enclosed in elements, where that data may consist of
nested (child) elements. Every XML document contains a single root (or document) element, and ele-
ments nested within the root element make up a hierarchy of data. Apart from the root element, XML
documents may contain a single XML declaration, and zero or more processor directives. Each element,
including the root element, has either a start tag and an end tag, or a single empty element tag. Start tags
and empty element tags can include attributes that consist of name/value pairs.
Here’s an example of an XML document:
<?xml version=”1.0” encoding=”utf-8” ?>
<foodStuffs>
<foodStuff category=”pizza”>
<name>Cheese and Tomato</name>
<size>10”</size>
<rating>4*</rating>
</foodStuff>
<foodStuff category=”pizza”>
<name>Four Seasons</name>
<size>8”</size>
<rating>1*</rating>
<isNasty />
</foodStuff>
</foodStuffs>
The XML declaration on the first line of the document identifies the version of XML to which the docu-
ment conforms and how it is encoded (that is, the character set used). The root element of the document
is
<foodStuffs>, which contains two <foodStuff> elements. Each <foodStuff> element has an
attribute called
category, and child elements called <name>, <size>, and <rating>, each of which
contains text data. Each of these elements consists of a start tag (for example,
<size>) and an end tag
that includes a preceding front slash (<
/size>). The second <foodStuff> element also contains an
empty element,
<isNasty>, which includes a trailing front slash to indicate that the element is empty.
One way of looking at this document is as an array of
foodStuff objects, each of which has properties
that are represented as attributes or child elements.
There are a few more rules concerning XML documents. For a start, they are case-sensitive.
<foodStuff> and <Foodstuff>, for example, are interpreted as two completely different elements.
Also, every start tag must have a matching end tag, and elements can’t overlap, that is to say that the fol-
lowing is illegal:
<element1><element2></element1></element2>
Here’s an example in which <element2> is correctly nested inside <element1>:
<element1><element2></element2></element1>
And in this example, neither element is nested in the other:
<element1></element1>
<element2></element2>
31
Database Fundamentals
44063c01.qxd:WroxBeg 9/12/06 10:31 PM Page 31