Being a flexible markup language toolkit, XML lets you use different character encodings, define your own grammars, and store parts of the document in many places. An XML parser needs to know about these particulars before it can start its work. You communicate these options to the parser through a construct called the document prolog.
The document prolog (if you use one) comes at the top of the document, before the root element. There are two parts (both optional): an XML declaration and a document type declaration. The first sets parameters for basic XML parsing while the second is for more advanced settings. The XML declaration, if used, has to be the first line in the document. Example 2-1 shows a document containing a full prolog.
Example 2-1. A document with a full prolog
<?xml version="1.0" standalone="no"?> The XML declaration <!DOCTYPE Beginning of the DOCTYPE declaration reminder Root element name SYSTEM "/home/eray/reminder.dtd" DTD identifier [ Internal subset start delimiter <!ENTITY smile "<graphic file="smile.eps"/>"> Entity declaration ]> Internal subset end delimiter <reminder> Start of document element ⌣ Reference to the entity declared above <msg>Smile! It can always get worse.</msg> </reminder> End of document element
The XML declaration is a small collection of details that prepare an XML processor for working with a document. It is optional, but when used it must always appear in the first line. Figure 2-3