Hi all,
What's the difference between the above standards?
Which should be used in webpages?
Thanks.
Kevin.
| SitePoint Sponsor |





Hi all,
What's the difference between the above standards?
Which should be used in webpages?
Thanks.
Kevin.


XHTML 1.0 is a reformulation of HTML 4.01 as an application of XML.
XHTML 1.1 is a reformulation of XHTML 1.0 Strict using Modularization of XHTML.
XHTML 1.0 is just an application of XML which uses the same set of element names and attributes (i.e., semantics) as HTML 4.01. It comes in three different DTDs (Strict, Transitional, Frameset) just like HTML 4.01.
XHTML 1.1 uses a concept called Modularization of XHTML, which means that the definition is split into a number of modules, which you can combine in any combination. There's something called XHTML Basic, for instance, which comprises just the essential modules for simple documents. XHTML 1.1 uses all modules (including a module for Ruby annotations that isn't part of any XHTML 1.0 DTD).
For most webpages, the logical choice is still HTML 4.01 Strict.
Why HTML? Because a large majority of users still use Internet Explorer, which does not support XHTML at all. Although you may use XHTML markup and serve it as text/html so that IE will accept the document, it's pointless since you cannot use any advantage that XHTML may have over HTML.
Why Strict? Because the Strict DTD enforces the separation of structure and presentation more than the Transitional DTD (which is mean to be used during a transitional phase when you convert old pre-HTML4 documents to a modern form).
If you absolutely have to write a few scattered '/' characters in your markup to feel manly (or whatever), or if you belong to the .0001% of Web authors who really need XHTML and can afford to ignore IE users, you should probably stick to XHTML 1.0 Strict.
If you serve the document as text/html, don't even think about using XHTML 1.1. It is not backwards-compatible with HTML and should not be served as text/html.
Birnam wood is come to Dunsinane
Sticking this thread so hopefully we don't have any more like it![]()


Off Topic:
Well, you can hope but I am sure the question will still get asked several thousand times.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?
just let me live in my fantasy world okay?Originally Posted by xhtmlcoder
![]()





Great thread, thanks for the post Autistic![]()


Right, if this thread is going to be sticky, I'll add another thing that seems to confuse many beginners.
What is required for a document to be treated like XHTML?
- A content type that says it's an application of XML.
- An XML namespace equal to 'http://www.w3.org/1999/xhtml'.
Content Type
The content type (a.k.a. media type or MIME type) must be sent by the server in the Content-Type HTTP header. You cannot change the content type with a META element, since the user agent needs to know what the document is before starting to parse it. There are three MIME types that will do this for XHTML:
- application/xhtml+xml
- application/xml
- text/xml
Using text/xml is not recommended, because there are some serious encoding issues with that MIME type. The recommended one is application/xhtml+xml.
Arguably, the server should not send any character encoding information in the Content-Type header, since X(HT)ML is meant to be a self-describing format where the encoding should be specified in the XML declaration. Thus the server should only send this:
and the document should start with something like this:Code:Content-Type: application/xhtml+xml
Note that if you use a MIME type of text/xml, the encoding will be US-ASCII unless the server sends encoding information in the Content-Type header. You cannot override it with an XML declaration (and, of course, not with a silly <meta/> element).Code:<?xml version="1.0" encoding="utf-8"?>
XML Namespace
The content type only tells the user agent that the document is an application of XML. Even if the MIME type is application/xhtml+xml, user agents don't know that it is, in fact, XHTML.
The thing that tells them that is the 'xmlns' attribute of the document's root element:
If you don't use this exact namespace URI, the document is not an XHTML document; it's general XML. That will cause some interesting effects in how the page is rendered... It will also cause certain elements to stop working, because the semantics is lost.HTML Code:<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
What about DOCTYPE?
Didn't I forget something in my list above? Surely, it's the doctype declaration that makes it XHTML? This techie stuff about HTTP headers and XML namespaces is just a smoke screen, isn't it? 'Fraid not.
The doctype declaration doesn't matter at all, as far as browsers are concerned. Browsers that support XHTML will not do doctype switching when the document is served as an application of XML. At least not to my knowledge. They will use their strict rendering mode.
The doctype is only used when you're validating your document. A validator must know with which flavour of XHTML you're claiming compliance. Browsers don't care.
Birnam wood is come to Dunsinane


The Doctype however matters with regard to referencing which syntax elements and attributes you are allowed to legally use within a strictly conforming XHTML document a Validating XML Parser may analyse it. A real XHTML UA does not necessary have to support client-side scripting either.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?

Great post Tommy and well stated !
Nadia
Unique CSS Templates by Nadia
Dreamweaver: Tutorials.Templates.CSS Designs
SitePoint Books |My Fireworks Tutorials 1 2
Follow me on Twitter | Community Team Advisor


True, but an XML parser does not have to read the DTD or schema definition, and AFAIK none does.Originally Posted by xhtmlcoder
So you could use a 'target' attribute for a link even with a Strict doctype, and it would work in the browser even though it's not valid. The only validation errors that are caught are well-formedness errors, and those are caught with a vengeance!![]()
Birnam wood is come to Dunsinane


You are thinking browsers Tommy I meant Validating XML Processors and some check for Valid XHTML but as you say most browsers just use Well-formedness Parsers.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?
Originally Posted by AutisticCuckoo
So if my documents starts like this:
Is there something wrong?Code:<!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">

That's called fake xhtml. When using real xhtml you have to put the ?xml version="1.0" encoding="utf-8"?> at the top of your document as serve up the proper mime type as well. But you can't do that yet because IE doesn't support it.
John Conde | Facebook | Twitter
Brainyminds Merchant Account Services I Love Code eBook Giant
Authorize.Net: AIM API | ARB API | CIM API Get the FREE code!
Merchant Accounts 101 | Ecommerce 101
No. The XML declaration is optional if you use utf-8 (or a subset of utf-8, such as us-ascii) or utf-16, or if you have specified the encoding with HTTP.Originally Posted by deronsizemore
Simon Pieters
Okay, I've got one that says it is "fake" and another says that there is nothing wrong....
Who is right here?
Stymiee: So if I use the proper xml declaration to serve the proper mime type at the top of the page IE users wont be able to view the page?





HelloOriginally Posted by deronsizemore
the browser that is used most, 80%~85% ? is not playing ball![]()
![]()
If you serve it as text/html then it's indeed "fake" XHTML; the browser will interpretet as if it was HTML. If you serve it as XML then it's "true" XHTML. You didn't say which it was, you only asked if there was anything wrong without the XML declaration.Originally Posted by deronsizemore
Simon Pieters


Simon is right, the XML declaration is optional under certain circumstances. The markup fragment you show seems correct, but we can't say whether it's 'right' or 'wrong' without knowing the MIME type. If it's application/xhtml+xml (or similar) it's 'right'. If it's text/html it's 'wrong' (i.e., not XHTML).Originally Posted by deronsizemore
The XML declaration has nothing to do with that. It's the application/xhtml+xml MIME type that IE doesn't support.Originally Posted by deronsizemore
You may serve it as application/xml, which IE supports. It will then be treated as XML. However, IE does not understand the XHTML namespace, so it will not be treated as XHTML, but as generic XML.
Birnam wood is come to Dunsinane


In otherwords the User Agent or Server may under certain circumstances determine the outcome as to whether it ends up being processed as the genuine article.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?
good,just want going to learn xml![]()

Have a few references/tutorials that could be of interest:
XHTML 1.1 Tutorial
XHTML Basic 1.0 Tutorial
XHTML Basic for mobile devices(what is XHTML Basic?)
XHTML - A combination of HTML and XML
Also, for those interested in using strict markup with XHTML in combination with Adsense, you should know there is a problem with Content-Type application/xhtml+xml.
According to w3c XHTML should be sent as application/xhtml+xml. There is allowed, however, to use text/html on less strict modules such as XHTML Transitional.
Since older browsers and IE doesn't understand application/xhtml+xml they can react by displaing the source code or not showing the document at all.
Therefor, to use application/xhtml+xml it is best to let the server know if a client/browser requesting a page can handle application/xhtml+xml, and - if the browser doesn't handle it - send it as text/html.
If PHP is used the following script can be used to send the different content types to different browsers:
If ASP and VBScript is used:Code:<?php if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") || stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")) { header("Content-Type: application/xhtml+xml; charset=iso-8859-1"); header("Vary: Accept"); echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); } else { header("Content-Type: text/html; charset=iso-8859-1"); header("Vary: Accept"); } ?>
Code:<% If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 Or InStr(Request.ServerVariables("HTTP_USER_AGENT"), "W3C_Validator") > 0 Then Response.ContentType = "application/xhtml+xml" Response.Write("<?xml version=""1.0"" encoding=""iso-8859-1""?>" & VBCrLf); Else Response.ContentType = "text/html" End If Response.Charset = "iso-8859-1" %>
Last edited by carlsson; Apr 7, 2006 at 00:18.





Hello
html or the X part ?
cool down


XHTML 1.0 (regardless of whether it's Strict, Transitional or Frameset) may be served as text/html, provided that you follow all the guidelines in Appendix C of the XHTML 1.0 specification.Originally Posted by carlsson
If you do, the document is HTML to all intents and purposes. You cannot use any XML-features such as namespaces or CDATA-sections.
That's a very primitive content negotiation script, which doesn't take into accound things like quality values (Q values). For instance, your script would serve application/xhtml+xml to a user agent sending this Accept header:Originally Posted by carlsson
Not really a good move, eh?Code:Accept: text/html; application/xhtml+xml;q=0![]()
Birnam wood is come to Dunsinane

Correct, I should have said XHTML 1.0 as a holeOriginally Posted by AutisticCuckoo
Correct again, this is a more advanced one:Originally Posted by AutisticCuckoo
Code:<?php $charset = "iso-8859-1"; $mime = "text/html"; function fix_code($buffer) { return (preg_replace("!\s*/>!", ">", $buffer)); } if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) { if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) { $xhtml_q = $matches[1]; if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) { $html_q = $matches[1]; if((float)$xhtml_q >= (float)$html_q) { $mime = "application/xhtml+xml"; } } } else { $mime = "application/xhtml+xml"; } } if($mime == "application/xhtml+xml") { $prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"; } else { ob_start("fix_code"); $prolog_type = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html lang=\"en\">\n"; } header("Content-Type: $mime;charset=$charset"); header("Vary: Accept"); print $prolog_type; ?>
Bookmarks