Forum Moderators: open
someone says something along the lines of xhtml strict dtd causing browser problems.
acouple of sites im working on at the moment use valid xhtml strict, and i havent noticed any problems in the browsers ive checked so far.
does any one have any further info?
thanks
As tedster and others have mentioned previously, the most important difference is between Transitional and Strict, not between HTML and XHTML.
Perhaps the poster was referring to XHTML 1.1, which should generally not be used?
xhtml 1.0 in html compatible mode is a *** that shouldn't have been invented.
see the following:
[xml.com...]
[w3.org...]
[hixie.ch...]
[devedge.netscape.com...]
you are asking for serious trouble if you want xhtml to work in IE x.x.
don't use xhmtl - use html 4.01 and avoid any problems.
the focus in developer circles on xhmtl as the holy grail is in my opinion completely misunderstood when you have to continuously compromise your coding in order to cater for IE x.x
[edited by: eelixduppy at 9:44 pm (utc) on Feb. 18, 2009]
XHTML served as text/html (ok with xhtml1.0, not with xhtml1.1) will probably work just fine (See BjarneDM's post for details).
XHTML served with an XML MIME type (application/xhtml+xml, text/xml) will cause some breakage. For example, document.write no longer works. You must use the DOM to add content to a page.
IE6 does not explicitly support XHTML, but it does support XML and styling of XML with CSS, so you can have a fully functional XHTML2 example [w3future.com] in IE6.
And I'm sorry for this stupid question as well...
My pages are all ASP. To change the mime type on my server, I would have to change it for the ASP extension, correct? It seems that would break other things, but I don't know until I try I suppose.
<added>
Okay, I changed the mime type on the server to "application/xhtml+xml". It still seems to be working fine in IE6+ and NN7.1. What should I be looking for?
</added>
<second edit>
Also changed the meta tag:
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
Still no problem found.
</second edit>
(linked from the validator's "you validate" page)
Read also BjarneDM's link to hixie.ch
Firstly, Lance, if your site is displaying in IE6, then you are not serving it as
application/xhtml+xml - check the page info in Mozilla and it will tell you the mime type currently used. The meta tag won't do anything as the page has already been given a mime type once you've got to there. Internet Explorer cannot display application/xhtml+xml at all. but then why does it validate
Because the validator does not check mime types - only well-formedness.
BjarneDM is not wrong but rather alarmist - XHTML 1.0 should be served as
application/xhtml+xml, but may be served as text/html. Doing the latter won't cause any problems in older browsers (but you get no real advantage over HTML 4). Back to XHTML 1.1. People tend to choose it because they see it as the latest W3C recommendation, and that it is the "strictest" standard with no depreated elements.
However, XHTML 1.1 is not actually the most up-to-date standard - XHTML 1.0 Second Edition came out afterwards with numerous errata and a few added features such as allowing an
id attribute on the html element - useful if you are styling that element in CSS. XHTML 1.1 was created as part of the XHTML modularization initiative, was split off before XHTML 1.0 Second Edition and thus does not include such changes. The role of XHTML 1.1 was to be an XHTML module to be used in combination with other XML types - for example, XHTML + SVG, or XHTML + MathML. It is not designed as a standalone application (although it can be used as such). Also, the lack of certain depreciated elements can mean that an XHTML 1.1 page is less accessible than an XHTML 1.0 page - for example, the
lang attribute can be used in XHTML 1.0 to identify the document language to screenreaders, etc. - however, you only have xml:lang in XHTML 1.1, which is not widely recognized. Finally, the virtually intractible question of acceptable mime-types for XHTML 1.1. Reading the documentation on the W3C website, there are two conflicting pieces of advice - one which says that XHTML 1.1 absolutely cannot be served as
text/html, and elsewhere saying that it should not, but may. In fact, there is no consensus regarding this question within the W3C, and so it is impossible to implement an XHTML 1.1 page served as text/html and be sure that it is fully-standards-compliant. XHTML 1.1 is the wrong standard with a lack of clarity in its specification, and has been superceded by XHTML 1.0 Second Edition. Best avoided.
Finally, it's only markup - using validated XHTML 1.1 served as
text/html is still far better than using Yahoo-style tag soup. You're still way ahead of the vast majority of other sites. Me, I much prefer HTML 4, but if you prefer XHTML, that's fine too.
Thank you for the very infomative post.
Firstly, Lance, if your site is displaying in IE6, then you are not serving it as application/xhtml+xml - check the page info in Mozilla and it will tell you the mime type currently used. The meta tag won't do anything as the page has already been given a mime type once you've got to there. Internet Explorer cannot display application/xhtml+xml at all.
Absolutely correct. It seems none of the actions I took server-side (IIS) caused the pages to be served application/xhtml+xml. I have since found an ASP script that detects browser capabilities and will serve appropriately. For testing, I disabled detection and just forced the site to be served application/xhtml+xml.
As expected, IE bailed completely and NN became unhappy. Surprisingly though, if I had the page already loaded in IE, then activated the new MIME type on the server and reloaded the page in IE, it fouled up less than NN did. I realize this is not really a valid test though.
Back to XHTML 1.1. People tend to choose it because they see it as the latest W3C recommendation, and that it is the "strictest" standard with no depreated elements.
Guilty...
Okay, back to XHTML 1.0 it is. For the mean time, with 1.0 it is legal to serve text/html, so I can leave it that way until I'm ready to work out everything that broke in NN when served application/xhtml+xml.
Thanks again.
-Lance
XHTML 1.0 Second Edition came out afterwards with numerous errata and a few added features such as allowing an id attribute on the html element - useful if you are styling that element in CSS.
Reading the documentation on the W3C website, there are two conflicting pieces of advice - one which says that XHTML 1.1 absolutely cannot be served as text/html, and elsewhere saying that it should not, but may.
XHTML 1.1 is the wrong standard with a lack of clarity in its specification, and has been superceded by XHTML 1.0 Second Edition
I agree that XHTML 1.0 is more backwards compatible.
HTH,
CK
The id attribute on the HTML element ... is not (and never was) an allowed attribute for the html element in the Strict DTD
If you cut-and paste this:
<?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" id="my-choice-of-id">
<head>
<title>Try me</title>
</head>
<body>
<h1>ID on HTML element</h1>
<p>This page is valid XHTML 1.0 Strict</p>
</body>
</html>
You will find that it validates. Swap the XHTML 1.0 Strict doctype for the XHTML 1.1 one, and it doesn't.
References:
Lance, when you serve pages as application/xhtml+xml, there are changes in the way the document is parsed and in the way CSS and Javascript function. If you are using CSS extensively, you will notice that styles applied to the body tag don't affect the whole page, just the content area, for example. You should try shifting rules up to the html element for starters. Also make absolutely sure of your capitalization. For Javascript, certain scripts won't work - including anything using document.write (eg. Adsense).
If you are interested in serving pages as application/xhtml+xml to those browsers that can cope with it, you need to read the HTTP_ACCEPT header and parse it for application/xhtml+xml. That means that IE, Googlebot and older browsers will get text/html and browsers such as Opera and Mozilla get the appropriate mime type. I've seen some ASP code around which does this - if I find it, I'll post it (I only use PHP myself).
Don't forget that when you are serving documents as application/xhtml+xml, one well-formedness error, however minor, and your page won't display at all - you'll just see an XML error. You have been warned!
Also, it validates as okay based on the dtd, but is it still XHTML 1.0 strict?
Anybody else have experience with that?
<%
Accept = Request.ServerVariables("HTTP_ACCEPT")
UA = Request.ServerVariables("HTTP_USER_AGENT")
If InStr(Accept, "application/xhtml+xml") > 0 OR InStr(UA, "W3C_Validator") > 0 Then
Response.ContentType = "application/xhtml+xml"
Response.Write("<?xml version=""1.0"" encoding=""utf-8""?>" & VbCrLf)
Else
Response.ContentType = "text/html"
End If
Response.Charset = "utf-8"
%>
And this replaces target="_whatever":
function ExternalLinks() {
/*Links Like This: <a href="http://www.foo.com" rel="external"> */
/*And Call onLoad: window.onLoad=externalLinks; */
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
Safari and Konqueror as well as the w3c validator don't send that in their http-accept string (as also evidenced in the asp script). Safari for instance is sending */* (I can handle everything), so I've decided on some other tests. This is my php script:
<?php
if ( stristr($_SERVER["HTTP_USER_AGENT"],"Mozilla/4.0") &&
!stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{
header("Content-type: text/html");?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="da">
<?php else {
header("Content-type: application/xhtml+xml");?>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/css/mozilla.css" type="text/css"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://mozilla.mathiesen.info/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<?php }?>
I assume that every user agent greater than Mozilla/4.0 (Mozilla, Safari, Konqueror and Opera are sendig Mozilla/5.0) is able to handle application/xhtml+xml and then do a check for if a 4.0 browser should be able to handle application/xhtml+xml
Incorrect. The id attribute on the HTML element has always been allowed for the Transitional DTD: [w3.org...]
It is not (and never was) an allowed attribute for the html element in the Strict DTD:
[w3.org...]I always thought it was the other way round. But checking the links you gave, both say ID is "implied" on the HTML tag.
I have been unable to find solutions to such simple problems in repeeated web searches, so I assume they are not well solved yet.
I do notice that people doing xhtml strict basically are just avoiding the problems by not using those techniques: ie, use the newest and greatest and have fewer options, less versatility, and more headaches. Sounds like a real winnner.....