Click to See Complete Forum and Search --> : XHTML or HTML?
Superfly1611
04-25-2004, 09:43 AM
My question is simple
I'm about to start to develop a new web site.
Is it worth taking the time to make it validate against the W3C XHMTL validator or would HTML 4 be fine?
In doing so will my site be more user friendly with other browsers?
fredmv
04-25-2004, 09:54 AM
You make it sound almost as if with HTML 4.01 you wouldn't have to — you still do. HTML 4.01 is perfectly acceptable but I prefer working with XHTML. If you're working with other XML applications (e.g., MathML or SVG) it would be ideal. I would also argue that XHTML 1.0 Strict specifically is nice because it gets rid of bad elements such as iframes.
David Harrison
04-25-2004, 10:32 AM
Here's (http://www.hixie.ch/advocacy/xhtml) a text-only article on the subject that I found at this (http://www.accessifyforum.com/viewtopic.php?t=1114) thread.
Personally I use XHTML 1.1 and a meta tag to specify application/xhtml+xml. I have recently found that it's a waste of time without a little snippet of server side code which I now use. Without the server-side stuff I may as well have just used text/html XHTML which is pretty much the same as HTML 4.01.
So I guess what I'm saying is, if you have a server-side language available use XHTML 1.1 but if not use HTML 4.01. Here's the code for PHP:
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
and for ASP:
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if
In both cases the code must go at the very start of the document, b before any code has been sent to the browser (even if it's just a line break).
sharkey
04-25-2004, 05:44 PM
Just out of curiosity what does that snippet of code do. I too use xhtml and was wondering whats its meaning is.
David Harrison
04-25-2004, 06:05 PM
If you want to use application/xhtml+xml then you have to have this meta tag (but obviously have your own character encoding):
<meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" />
But then you also need some server side code that tells the browser to interpret what it's receiving is application/xhtml+xml (so long as the browser can handle it). The code detects whether the browser can handle application/xhtml+xml and if it can't it tells the browser that it's sending normal text/html.
Here is some simplified code from the include file that I use on Hackus (it's ASP):
<%
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if
Response.Charset="windows-1252"
sub top(title) %><?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hackus<%= title %></title>
<meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" />
<style type="text/css" media="all">
@import "styles.css";
</style>
</head>
<body>
<% end sub %>
The Cheat
04-25-2004, 06:36 PM
Personally i think its best to go with html 4.01 strict. You dont have to worry about mime type issues and browser support.
Currently, sending xhtml as text/html is considered harmful (http://hixie.ch/advocacy/xhtml), and sending xhtml as application/xhtml+xml is only supported by Mozilla and newer versions of opera. (complete list (http://www.w3.org/People/mimasa/test/xhtml/media-types/results)) Also, you have to use a server-side language (http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html) to truly send it as application/xhtml+xml.. which can be a pain when just trying to output a simple static page...
as fredmv said here (http://forums.webdeveloper.com/showthread.php?s=&threadid=33146&perpage=15&pagenumber=2) , "HTML 4.01 can be used to create perfectly semantic documents and you won't have to worry about MIME type problems and browser support."
Paul Jr
04-25-2004, 09:29 PM
Originally posted by lavalamp
Here's the code for PHP:
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary...
David Harrison
04-25-2004, 10:01 PM
Originally posted by Paul Jr
Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary... Well the red part certainly is:
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
:p
But seriously, I don't know PHP very well, Robert Wellock pulled that code off a web-site, pm'ed the code to me and I don't use it. I'm an ASP guy. ;)
the section in blue tells the w3 validator to take the application/xhtml+xml rather than the text/html, I really don't think this has any effect on the validation other than it makes your doctype slightly more strict
PeOfEo
04-25-2004, 10:37 PM
I use html 4.01 transitional more often because it is less to worrie about when I have data driven sites and they users control the content and then I have tons of forms running around. But if you are not heavy on the forms and xhtml would be the way to go.
Paul Jr
04-25-2004, 11:38 PM
Originally posted by samij586
the section in blue tells the w3 validator to take the application/xhtml+xml rather than the text/html, I really don't think this has any effect on the validation other than it makes your doctype slightly more strict
The W3 validator seems to do just fine without that piece of code (minus the last bracket :D ); I was playing around last night and I validated one of the pages that used just
<?php
if(stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {
header("content-type: application/xhtml+xml");
}
else {
header("content-type: text/html");
}
?>
The validator was fine, and the content type was application/xhtml+xml.
Originally posted by Paul Jr
The validator was fine, and the content type was application/xhtml+xml. Yes, but if you look at the content-type in the validation results, it will say text/html even though you are sending it as application/xhtml+xml. The only reason for doing it, really, is to have the content-type show up as application/xhtml+xml on the W3C's validator.
Robert Wellock
04-26-2004, 08:11 AM
They might have updated the Validator by now, but when sent as a referrer you had to explicitly set the MIME.
As for XHTML 1.0 yes you can use Transtional as text/html.