Information Technology Reference
In-Depth Information
2.3.1 XML Basics
Let us return to the simple XML file in Listing 2.1 to briefly explain the basic
structure of an XML document.
The first part of the document, called the prolog , consists of an XML decla-
ration which denotes the XML version, and optionally the character encoding,
etc., plus an optional document type definition. This DTD can be defined ex-
ternally (as in the example), or within the document itself. Immediately after
the prolog, the XML document starts with the designated document element
(the root). Each XML element is delimited by start and end tags and can con-
tain one or more subelements, text, or a mixture of both text and elements.
Each element must end with a closing tag (an element without content can be
abbreviated to < tagname /> instead of writing < tagname ></ tagname > ); at-
tribute values must be quoted and must not appear in end tags, and elements
may not overlap. That is more or less about it. Any document following this
syntactical structure is considered a well-formed XML document. The infor-
mation contained in a well-formed XML document can be viewed as a tree ,
having the document element as its root, as shown in Fig. 2.5.
Fig. 2.5. An XML tree
Furthermore, XML documents which obey the rules for usable tag names
and attributes defined in an associated DTD (or other schema definition such
as XML Schema, see below) are called valid .
Document Type Definitions in XML
As we have mentioned DTDs several times already in the context of SGML
and XML, it is worthwhile to illustrate DTDs with a small example. As already
Search WWH ::




Custom Search