XML Declaration [XML Standards]
The XML declaration typically appears as the first line in an XML document. The XML declaration is not required, however, if used it must be the first line in the document and no other content or white space can precede it.
The XML declaration in the document map consists of the following:
The version number,
This is mandatory. Although the number might change for future versions of XML, 1.0 is the current version.
The encoding declaration,
<?xml version="1.0" encoding="UTF-8"?>
This is optional. If used, the encoding declaration must appear immediately after the version information in the XML declaration, and must contain a value representing an existing character encoding.
An XML declaration can also contain a standalone declaration, for example,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>. Like the encoding declaration, the standalone declaration is optional. If used, the standalone declaration must appear last in the XML declaration.
The encoding declaration identifies which encoding is used to represent the characters in the document. Although XML parsers can determine automatically if a document uses the UTF-8 or UTF-16 Unicode encoding, this declaration should be used in documents that support other encodings.
For example, the following is the encoding declaration for a document that uses the ISO-8859-1 (Latin 1).
<?xml version="1.0" encoding="ISO-8859-1"?>
Case in the value specified is not considered by the encoding declaration.
The following is the encoding declaration for a document that uses the Japanese encoding method Shift-JIS.
<?xml version="1.0" encoding="Shift-JIS"?>
The standalone declaration indicates whether a document relies on information from an external source, such as external document type definition (DTD), for its content.
If the standalone declaration has a value of
"yes", for example,
<?xml version="1.0" standalone="yes"?>, the parser will report an error if the document references an external DTD or external entities.
Leaving out the standalone declaration produces the same result as including a standalone declaration of
"no". The XML parser will accept external resources, if there are any, without reporting an error.