Forum Moderators: open

Message Too Old, No Replies

Placing XML declaration before XHTML Doctype?

         

tonynoriega

3:54 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



afternoon all.. im still checking a site that i am now managing...

we have this doctype declaration on our site:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

now with this declaration, shouldnt there be a content type declaration or a xml declaration..? i.e.

Content-Type: text/html; charset=utf-8

or

<?xml version="1.0" encoding="utf-8" ?>

im confused as to which one we should be using?

encyclo

11:55 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, you should never place an XML prolog (or anything else) before an XHTML doctype when serving the content as HTML. The presence of a prolog will change the rendering mode in certain older browsers (specifically in IE6), meaning that the page will be parsed in quirks mode rather than standards-compliant mode.

You should, however, always declare the document charset, either via a HTTP header or with a meta charset element placed before the

title
element.

tonynoriega

4:08 pm on Sep 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this is what the w3c recommended... can i just change the declaration to xhtml transitional?

<?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" xml:lang="en" lang="en">

<head>
<title>An XHTML 1.0 Strict standard template</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>

<body>

<p>… Your HTML content here …</p>

</body>
</html>

encyclo

1:37 am on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Technically-speaking the W3C template is not wrong, but it doesn't reflect the reality of current and legacy browsers.

This would be better as a basic XHTML 1.0 Transitional template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.0 Transitional template</title>
</head>
<body>

<p>… Your HTML content here …</p>

</body>
</html>

As for the following line:

<meta http-equiv="Content-Style-Type" content="text/css" />

It should be present in theory, in practice it is not required. This is because the default, and indeed only existing style type currently supported in browsers is

text/css
.

For the meta charset element, the recommendation is that it be placed as high as possible in the head section, before any content (including the title element). In practice, placing it after the title (as in the W3C template) is not a problem.