Reputation:
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" ?>
Upvotes: 3
Views: 139
Reputation: 111621
The <?xml ...?>
construct,
<?xml version = "1.0" encoding = "utf-8" ?>
is an XML declaration, and the xml
part does not vary per type of XML file. It should be the same for an XHTML file (which is XML by definition).
Notes:
xml
part 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:
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>An XHTML 1.0 Strict standard template</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<p>… Your HTML content here …</p>
</body>
</html>
Upvotes: 3
Reputation: 163342
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.
Upvotes: 1