Datasheet

The XML declaration is followed by the document’s root element, which is usually referred to as the
document element. In the following example, the document element is named books:
<?xml version=”1.0”?>
<books>
...
</books>
The document element is not optional; every document must have one. The following XML is legal
because book elements are nested within the document element books:
<?xml version=”1.0”?>
<books>
<book>
...
</book>
<book>
...
</book>
</books>
The document in the next example, however, is not legal because it lacks a document element:
<?xml version=”1.0”?>
<book>
...
</book>
<book>
...
</book>
If you run the previous XML through a parser, the XML will not load properly, complaining about the
non-existence of the root element.
Elements
Element names conform to a set of rules prescribed in the XML specification that you can read at
http://www.w3.org/TR/REC-xml. The specification essentially says that element names can consist of
letters or underscores followed by letters, digits, periods, hyphens, and underscores. Spaces are not
permitted in element names. Elements are the building blocks of XML documents and can contain data,
other elements, or both, and are always delimited by start and end tags. XML has no predefined elements;
you define elements as needed to adequately describe the data contained in an XML document. The
following document describes a collection of books:
<?xml version=”1.0”?>
<books>
<book>
<title>XSLT Programmers Reference</title>
<author>Michael Kay</author>
<year>2003</year>
</book>
<book>
5
Introduction to XML
04_596772 ch01.qxd 12/13/05 11:17 PM Page 5