XHTML or HTML?

liunx

Guest
My question is simple<br />
I'm about to start to develop a new web site.<br />
Is it worth taking the time to make it validate against the W3C XHMTL validator or would HTML 4 be fine?<br />
In doing so will my site be more user friendly with other browsers?<!--content-->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.<!--content-->Here's (<!-- m --><a class="postlink" href="http://www.hixie.ch/advocacy/xhtml">http://www.hixie.ch/advocacy/xhtml</a><!-- m -->) a text-only article on the subject that I found at this (<!-- m --><a class="postlink" href="http://www.accessifyforum.com/viewtopic.php?t=1114">http://www.accessifyforum.com/viewtopic.php?t=1114</a><!-- m -->) thread.<br />
<br />
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.<br />
<br />
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:<br />
<br />
<br />
<?php<br />
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||<br />
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))<br />
{<br />
header("Content-type: application/xhtml+xml");<br />
}else {<br />
header("Content-type: text/html");<br />
}<br />
?><br />
and for ASP:<br />
<br />
<br />
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then<br />
Response.ContentType = "application/xhtml+xml"<br />
else<br />
Response.ContentType = "text/html"<br />
end if<br />
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).<!--content-->Just out of curiosity what does that snippet of code do. I too use xhtml and was wondering whats its meaning is.<!--content-->If you want to use application/xhtml+xml then you have to have this meta tag (but obviously have your own character encoding):<br />
<br />
<br />
<meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" /><br />
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.<br />
<br />
Here is some simplified code from the include file that I use on Hackus (it's ASP):<br />
<br />
<br />
<br />
<%<br />
<br />
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then<br />
Response.ContentType = "application/xhtml+xml"<br />
else<br />
Response.ContentType = "text/html"<br />
end if<br />
<br />
Response.Charset="windows-1252"<br />
<br />
sub top(title) %><?xml version="1.0" encoding="windows-1252"?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" <br />
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><br />
<br />
<head><br />
<br />
<title>Hackus<%= title %></title><br />
<br />
<meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" /><br />
<br />
<style type="text/css" media="all"><br />
@import "styles.css";<br />
</style><br />
<br />
</head><br />
<br />
<body><br />
<br />
<% end sub %><!--content-->Personally i think its best to go with html 4.01 strict. You dont have to worry about mime type issues and browser support. <br />
<br />
Currently, sending xhtml as text/html is considered harmful (<!-- m --><a class="postlink" href="http://hixie.ch/advocacy/xhtml">http://hixie.ch/advocacy/xhtml</a><!-- m -->), and sending xhtml as application/xhtml+xml is only supported by Mozilla and newer versions of opera. (complete list (<!-- m --><a class="postlink" href="http://www.w3.org/People/mimasa/test/xhtml/media-types/results">http://www.w3.org/People/mimasa/test/xh ... es/results</a><!-- m -->)) Also, you have to use a server-side language (<!-- m --><a class="postlink" href="http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html">http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html</a><!-- m -->) to truly send it as application/xhtml+xml.. which can be a pain when just trying to output a simple static page...<br />
<br />
as fredmv said here (<!-- m --><a class="postlink" href="http://forums.webdeveloper.com/showthread.php?s=&threadid=33146&perpage=15&pagenumber=2">http://forums.webdeveloper.com/showthre ... genumber=2</a><!-- m -->) , "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."<!--content-->Originally posted by lavalamp <br />
Here's the code for PHP:<br />
<br />
<br />
<?php<br />
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||<br />
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))<br />
{<br />
header("Content-type: application/xhtml+xml");<br />
}else {<br />
header("Content-type: text/html");<br />
}<br />
?><br />
<br />
Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary...<!--content-->Originally posted by Paul Jr <br />
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:<br />
<br />
<?php<br />
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||<br />
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))<br />
{<br />
header("Content-type: application/xhtml+xml");<br />
}else {<br />
header("Content-type: text/html");<br />
}<br />
?><br />
<br />
:p<br />
<br />
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. ;)<!--content-->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<!--content-->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.<!--content-->Originally posted by samij586 <br />
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 <br />
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<br />
<br />
<?php<br />
if(stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {<br />
header("content-type: application/xhtml+xml");<br />
}<br />
else {<br />
header("content-type: text/html");<br />
}<br />
?><br />
<br />
The validator was fine, and the content type was application/xhtml+xml.<!--content-->Originally posted by Paul Jr <br />
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.<!--content-->They might have updated the Validator by now, but when sent as a referrer you had to explicitly set the MIME.<br />
<br />
As for XHTML 1.0 yes you can use Transtional as text/html.<!--content-->
 
Back
Top