The XML Declaration
XML documents should (but do not have to) begin with an
XML declaration. The XML declaration looks like a
processing instruction with the name xml and with version, standalone, and encoding pseudo-attributes. Technically,
it’s not a processing instruction, though; it’s just the XML
declaration, nothing more, nothing less. Example 2-7 demonstrates.
<?xml version="1.0" encoding="ASCII" standalone="yes"?> <person> Alan Turing </person>
XML documents do not have to have an XML declaration. However,
if an XML document does have an XML declaration, then that declaration
must be the first thing in the document. It must not be preceded by
any comments, whitespace, processing instructions, and so forth. The
reason is that an XML parser uses the first five characters (<?xml) to make some reasonable guesses
about the encoding, such as whether the document uses a single-byte or
multibyte character set. The only thing that may precede the XML
declaration is an invisible Unicode byte-order mark. We’ll discuss
this further in Chapter 5.