<?xml?> Declaration Examples

Examples of the xml declaration in HTML 5
<?xml?> declaration for XML version 1.0

The <?xml?> declaration appears at the very beginning of an HTML document:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/site-template.xsl"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
   ...
</html>

It is recommended that the encoding be specified using the preferred (MIME) name as specified in the IANA's Official Names for Character Sets. The standalone attribute can also be coded with the value yes, since the default is "no". Some examples:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
<?xml version="1.0" encoding="EUC-JP" standalone="yes"?>
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<?xml version="1.0" encoding="ISO-10646-UCS-2" standalone="yes"?>
<?xml version="1.0" encoding="ISO-10646-UCS-4" standalone="yes"?>

If the standalone attribute is omitted it does not matter unless the HTML browser would normally try to use external declarations, in the form of the HTML DTD, to interpret the document. standalone="yes" prevents it from using those external declarations, which would be for older versions of HTML rather than HTML 5 and later.

<?xml?> declaration for XML version 1.1

XML version 1.1 added support for record-oriented files, such as those used on mainframe systems, by including the next line (&#x85;) and line separator (&#2028;) characters to the list of valid line-ending characters.

<?xml version="1.1" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="/site-template.xsl"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
   ...
</html>

XML version 1.1 also provides more generic language support by allowing almost all Unicode characters in element type names, attribute names, enumerated attribute values and processing instruction targets, but since these items are defined by the HTML specifications, HTML documents do not take advantage of this new feature.