In the beginning of an XHTML file, why do we use "xml" in the following construct:
<?xml version = "1.0" encoding = "utf-8" ?>
Shouldn't it be:
<?xhtml version = "1.0" encoding = "utf-8" ?>
Shouldn't it be: Shouldn't it be: Shouldn't it be:
In the beginning of an XHTML file, why do we use "xml" in the following construct:
<?xml version = "1.0" encoding = "utf-8" ?>
Shouldn't it be:
<?xhtml version = "1.0" encoding = "utf-8" ?>
On
Q: Why do we use <?xml..?>?
A: Because that's what the spec says we must use.
Q: Why does the spec say that?
A: Because the relationship between XHTML and XML is that XHTML is a particular XML vocabulary. The XML declaration is there to give information to the XML parser (about the version of XML and the encoding of the file), and the XML parser handles any XML file regardless of what vocabulary is used.
It could have been designed differently, of course. But it wasn't.
The
<?xml ...?>construct,is an XML declaration, and the
xmlpart does not vary per type of XML file. It should be the same for an XHTML file (which is XML by definition).Notes:
xmlpart is fixed; it never varies in an XML declaration.<?xhtml ... ?>declaration; use<?xml ... ?>.XHTML Prolog Example:
Per the W3C Recommended list of Doctype declarations, where you can find other examples as well: