Section 15.4.  The prolog

Prev don't be afraid of buying books Next

15.4. The prolog

XML documents may start with a prolog that describes the XML version ("1.0" or "1.1", for now), document type, and other characteristics of the document.

The prolog is made up of an XML declaration and a document type declaration, both optional.

Caution

Some Microsoft Office applications require an XML declaration in order to recognize and process the document as XML.




The XML declaration must precede the document type declaration if both are provided. Also, comments, processing instructions, and white space can be mixed in among the two declarations. The prolog ends when the first start-tag begins.

Example 15-8 is a simple prolog.

Example 15-8. A simple prolog
 <?xml version="1.0"?> <!DOCTYPE book SYSTEM "http://www.oasis-open.org/.../docbookx.dtd"> 

This prolog says that the document conforms to XML version 1.0 and declares adherence to a particular document type, book.

15.4.1 XML declaration

The XML declaration has three parts; the last two are optional. A minimal XML declaration looks like this:

Example 15-9. Minimal XML declaration
 <?xml version="1.0"> 

Example 15-10 is a more expansive one, using all of its parts.

Example 15-10. More expansive XML declaration
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 

Although the parts have the same syntax as attributes, there is an important difference. The parts are strictly ordered whereas attributes can be specified in any order.

The third part, the standalone document declaration, is rarely used and arguably useless; we'll say no more about it!

15.4.1.1 Version info

The version info part of the XML declaration declares the version of XML that is in use. It is required in all XML declarations, although the XML declaration itself is optional. At the time of writing, the only permitted version strings are "1.0" and "1.1". If you leave out the entire XML declaration (thereby leaving out the version) then your document is presumed to be an XML 1.0 (not 1.1) document.

The XML version information is part of a general trend towards information representations that are self-identifying. This means that you can look at an XML document and (if it has the declaration) know immediately both that it is XML and what version of XML it uses. As more and more document representations become self-identifying, we will be able to stop relying on error-prone identification schemes like file extensions.

15.4.1.2 Encoding declaration

The encoding declaration part describes the encoding that is used. If omitted, it defaults to a Unicode encoding called UTF-8 which incorporates the commonly-used 7-bit ASCII. Therefore, you need only use the encoding declaration for a national or regional encoding like Russia's KOI8-R, Western Europe's ISO-8859-1 or Japan's Shift-JIS, as shown in Example 15-11.

Example 15-11. Encoding declaration
 <?xml version="1.0" encoding="KOI8-R"?> 

15.4.2 Document type declaration

After the XML declaration (if present) and before the first element, there may be a document type declaration which declares the document type that is in use in the document. A "book" document type, for example, might be made up of chapters, while a letter document type could be made up of element types such as ADDRESS, SALUTATION, SIGNATURE, and so forth.

The document type declaration is at the heart of the concept of validity, which makes applications based on XML robust and reliable. It includes the markup declarations that express the document type definition (DTD).

The DTD is a formalization of the intuitive idea of a document type. The DTD lists the element types available and can put constraints on the occurrence and content of elements and other details of the document structure. This makes an information system more robust by forcing the documents that are part of it to be consistent.

A schema definition can also be used for this purpose, but other means must be used to associate it with documents. There are several schema languages; we discuss the official W3C one in Chapter 22, "XML Schema (XSDL)", on page 466.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net