Page 1 of 1
Which DOCTYPE to use for XHTML?
Posted: Tue Aug 05, 2008 12:12 pm
by jayshields
This might sound like a silly question, but I just can't find a good answer anywhere.
So, I've written XHTML1.0 Strict mark up. So I should use the following at the top of every page:
Code: Select all
<?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">
Fair enough, but without the proper MIME type, it's not even going to be treated as XHMTL (if someone would care to elaborate on this I would appreciate it). So then I use this in my PHP scripts:
Code: Select all
header("Content-Type: application/xhtml+xml");
OK, so now Internet Explorer (7) wants me to download my PHP scripts instead of display them.
So what do I do? Keep the DOCTYPE, but forget about the MIME type? Change my DOCTYPE to HTML 4.01 Strict and then I can omit the MIME type? Won't I have to change some of the mark up if I want to use the HTML 4.01 DOCTYPE?
Re: Which DOCTYPE to use for XHTML?
Posted: Tue Aug 05, 2008 2:58 pm
by kaszu
IE just doesn't support it:
http://www.w3.org/People/mimasa/test/xh ... es/results
I believe, as long as code is semantically correct, maintainable and valid, XHTML is as good as HTML.
I use XHTML and "text/html" myself.
And yes, you will need to make some changes if you want to switch to HTML from XHTML
Re: Which DOCTYPE to use for XHTML?
Posted: Tue Aug 05, 2008 4:32 pm
by jayshields
Thanks for the link, that's a keeper.
I already know that XHTML is as good if not better than HTML, and I already know that changes have to be made to go from HTML to XHTML, but I'm not sure if XHTML is completely backwards-compatible or not.
You say you use XHTML and text/html MIME type, which is what I'm doing currently, but
Wikipedia says it won't be treated as XHTML - but I don't know what that means.
Ok, I've found this
http://www.w3.org/TR/xhtml-media-types/ which pretty much clears things up. Basically, I SHOULD be using application/html+xml but I MAY use text/html, and since IE doesn't support application/html+xml then I have to use text/html.
I think what Wikipedia refers to as XHTML not being treated correctly means that browsers won't be able to detect parse errors like it could if it was an XML MIME type.
Re: Which DOCTYPE to use for XHTML?
Posted: Tue Aug 05, 2008 5:19 pm
by kaszu
I haven't experienced any problems with browsers and parsing errors yet (except in IE).
In PHP You can check if $_SERVER['HTTP_ACCEPT'] contains "application/xhtml+xml" and then pass appropriate header.
Re: Which DOCTYPE to use for XHTML?
Posted: Tue Aug 05, 2008 6:27 pm
by jayshields
Ah, didn't know about that. Will probably go down that road then, thanks.
And I meant "might not parse errors" as in, if you have the proper XHTML MIME type then, for example, Firefox won't load the page at all if the document isn't well-formed. It will just show an XML related error.
Re: Which DOCTYPE to use for XHTML?
Posted: Thu Aug 07, 2008 8:28 am
by matthijs
This is quite an old discussion. A few links which might be interesting
http://annevankesteren.nl/2005/10/rise-of-html
http://www.456bereastreet.com/archive/2 ... _properly/
http://www.456bereastreet.com/archive/2 ... ly_matter/
http://www.robertnyman.com/2005/11/02/html-or-xhtml/
In the end:
- real xhtml is never going to be the thing it seems (maybe HTML5?, who knows)
- practically it won't matter too much if you choose html or xhtml. more important is that you choose a strict doctype and write clean html
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 12:37 am
by JAB Creations
HTML5 is a joke in it's current state and is neither forward nor backwards compatible. Additionally <all_elements href="virus.exe" is one of the stupidest things anyone has every thought up.
XHTML 1.0 Strict is and will remain for a very long time the
best option however you'll want to do content negotiation as IE will not add XHTML support until their CSS is solid...so this is a big maybe for IE9.
My site supports
media type (mime) and
doctype options so you can manually test out how various combinations of doctypes and media types interact with various browsers. Opera 7+, Gecko 0.9+, and from what I can tell most if not all versions of WebKit all support XHTML (true XHTML requires application/xhtml+xml support). Again IE9 is the earliest we
may see XHTML support.
The script below will serve the best media type the given browser can support. If you use XHTML 1.0 Strict you will
not have to worry about serving the page either as text/html or application/xhtml+xml. However going with a lower or higher doctype is not permitted to serve the page the page as either or (though it will still technically work). Lastly do not serve pages as application/xhtml+xml to friendly bots.
Code: Select all
<?php
if ($settings->get('mediatype') == "ns")
{
$mime = (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) ? "application/xhtml+xml" : "text/html";
header("content-type:$mime;charset=$charset");
}
?>
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 4:39 am
by matthijs
JAB Creations wrote:
XHTML 1.0 Strict is and will remain for a very long time the best option
Why?
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 6:19 am
by JAB Creations
You didn't read my post.
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 7:19 am
by matthijs
JAB Creations wrote:You didn't read my post.
I read your post. But don't find an explanation of why XHTML would be better then HTML.
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 9:55 am
by JAB Creations
First line.
...and if you're referring to HTML 4 versus XHTML then doing XHTML properly will force you to code better quality overall.
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 10:48 am
by matthijs
Sorry JAB I'm trying to understand what your argument is but the way our discussion goes leaves me without a clue
First lines:
JAB Creations wrote:HTML5 is a joke in it's current state and is neither forward nor backwards compatible. Additionally <all_elements href="virus.exe" is one of the stupidest things anyone has every thought up.
XHTML 1.0 Strict is and will remain for a very long time the best option however you'll want to do content negotiation as IE will not add XHTML support until their CSS is solid...so this is a big maybe for IE9.
I am referring to HTML4 yes.
and if you're referring to HTML 4 versus XHTML then doing XHTML properly will force you to code better quality overall
That's not something I believe. Care to elaborate? I think it's more about having a strict standard (html4 strict or xhtml strict) then it is about html vs xhtml. I have sites in HTML4 strict now, rewriting them to "XHTML" would mean adding a few slashes in a few tags like img tags. That's all. In my opinion trying to code
real XHTML (and having to deal with the whole browser sniffing stuff) is only a hassle and has no advantages as long as you have visitors using IE.
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 6:57 pm
by JAB Creations
You can't use things such as document.write in JavaScript however people are becoming fan boys of jQuery too easily. They won't know how to target an id and insert the data they wish to change for example.
Re: Which DOCTYPE to use for XHTML?
Posted: Sat Aug 09, 2008 7:08 pm
by Eran
@JAB Creations:
Using real XHTML is nothing more than a pet peeve and can not be considered seriously for a production site. HTML is the de-facto standard (at least while IE still has over 75% of the market share), and HTML 5 is definitely a step in the right direction. Don't know where you got your bias from, but it's misdirected.