+ Reply to Thread
Results 1 to 6 of 6

Thread: Xhtml

  1. #1
    NLC Meksilon is on a distinguished road Meksilon's Avatar
    Join Date
    Jan 2002
    Location
    Canberra, Australia
    Posts
    1,151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Xhtml

    Now I'm nearing completion of a pure XHTML website, I thought I'd talk about it for a moment.

    Most websites do not use real XHTML. They simply use HTML with an XHTML doctype.

    What's the difference?

    Well here's the normal HTML doctype we all know:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    Okay. Here's the XHTML doctype:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    It makes no difference what version you use.

    XHTML is NOT HTML, it is a recoding of HTML into XML. And ALL XML documents must have the XML declaration tag right at the top:

    <?xml version='1.0' encoding='utf-8'?>

    Of course, this now means that it can't be read by HTML browsers, only XML applications (after all that's what XML is for anyway). When serving it from a webserver, the MIME type is application/xhtml+xml.

    The problem is because people use XHTML when they should be using HTML, they simply remove thee XML declaration tag and serve the document as regular HTML using the text/html MIME type. But of course this means that it can only be parsed as an HTML document, not an XML document! This, of course, means there are no benefits over using the HTML doctype - and there are disadvantages. For instance, most browsers will be triggered into quirks mode to parse it since as an HTML document it's missing its DOCTYPE.

    Even browsers that choose to parse it as XML overriding the doctype and ignoring the missing xml declaration tag will usually fail to load it and revert to loading it through their HTML parser. This is because XML is not allowed to contain any errors, even a single error usually means that the XML parser fails to load the document.

    So in essence, my design serves the document by XML correctly with the right MIME type; and for browsers that don't like XML they get the XML tag and XHTML doctype removed and replaced with a regular HTML doctype, served as text/html.

    Oh, and an easy way to test whether your document is really being read XML is to self-close a script tag within the <head> tags as such: <script type="text/javascript" />

    Any browser interpreting it as HTML can't see a close script tag and won't display any of your webpage content.
    Last edited by Meksilon; April 24th, 2012 at 22:45.

  2. #2
    NLC Ben has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond reputeBen has a reputation beyond repute Ben's Avatar
    Join Date
    Jun 2001
    Location
    Atlanta
    Posts
    7,537
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'll add that there's no reason to use Transitional unless you want to use deprecated tags like <center> and <font...> or deprecated attributes like bgcolor ... stick with Strict and use span tags or something ... no formatting should be in the XHTML document itself, but in a separate CSS file.

    just FYI
    Last edited by Ben; April 27th, 2012 at 00:18.
    "They're polyurethane --- toys, Joe. They aren't capable of judgment."

  3. #3
    NLC sander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to beholdsander k is a splendid one to behold sander k's Avatar
    Join Date
    Jan 2008
    Location
    Netherlands
    Posts
    2,486
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this going to be better for search engines and will all browsers be able to read the website?
    Free Web Proxy: WP Like!

  4. #4
    NLC Meksilon is on a distinguished road Meksilon's Avatar
    Join Date
    Jan 2002
    Location
    Canberra, Australia
    Posts
    1,151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Here's a slightly more simplified version of the script I wrote to take care of it. Basically it automatically detects whether to send as html or xhtml, and can be overriden by the query string (for testing, etc).
    PHP Code:
    <?php
    $qstring
    =stripslashes($_SERVER['QUERY_STRING']);
    $usehtml=($qstring=='html');
    $u---html=($qstring=='xhtml');
    if(!
    $qstring=='')$robots='<meta name="robots" content="noindex,nofollow,noarchive" />';
    else 
    $robots='<meta name="robots" content="index,follow,noarchive" />';
    if(!
    $usehtml && !$u---html){
      
    $u---html=stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml');
      if(
    $u---html && preg_match("/text\/html;q=0(\.[1-9]+)/i",$_SERVER["HTTP_ACCEPT"],$qtest2)){
        if(
    preg_match("/application\/xhtml\+xml;q=0(\.[1-9]+)/i",$_SERVER["HTTP_ACCEPT"],$qtest1))
          
    $u---html=($qtest1[1]>=$qtest2[1]);
        else
          
    $u---html=false;
      }
    }
    if (
    $u---html) {
      
    $conttype='application/xhtml+xml';
      
    $dtype="<?xml version='1.0' encoding='utf-8'?"'>'chr(10). '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'chr(10). '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'chr(10);
      
    $htmltg='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'chr(10);
    }
    else {
      
    $usehtml=true;
      
    $conttype='text/html';
      
    $dtype='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'chr(10);
      
    $htmltg='<html lang="en">'chr(10);
    }
    header('Content-type: '$conttype);
    header('Cache-Control: must-revalidate');
    header('Expires: 'gmdate('D, d M Y H:i:s',time()+3600). ' GMT');
    echo 
    $dtype$htmltg;
    ?>
    Here's my website's first real page: Toshiba BDX3200KY Firmware. It does not yet implement the correct design of the website, just an example of the HTML/XHTML duality in action (try the W3 verification links at the bottom of the page). Also, only mozilla actually highlights the XHTML source code correctly (if you view it). Chrome and Opera's source viewer incorrectly stops highlighting at the script tag as if the rest of the website is a javascript! Yet they parse the website correctly.
    Last edited by Meksilon; April 30th, 2012 at 01:24.

  5. #5
    Pro Member TehGuy is just really niceTehGuy is just really niceTehGuy is just really niceTehGuy is just really niceTehGuy is just really nice TehGuy's Avatar
    Join Date
    Nov 2003
    Location
    Arkansas, United States
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your page is getting thrown into Quirks mode in IE7/8

  6. #6
    NLC Meksilon is on a distinguished road Meksilon's Avatar
    Join Date
    Jan 2002
    Location
    Canberra, Australia
    Posts
    1,151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TehGuy View Post
    Your page is getting thrown into Quirks mode in IE7/8
    True, however any page that contains a single error in XHTML it automatically parsed as HTML rather than XML in browsers; quirks mode or not (test it for yourself). IE9 displays the XMHTL fine and highlights the source code correclty (whereas Opera and Chrome do not; and Safari doesn't even hilight at all).

+ Reply to Thread

Similar Threads

  1. PSD to xHTML including various CMS
    By wonderfoundry in forum Ads & Offers
    Replies: 0
    Last Post: December 27th, 2009, 20:30
  2. Need help - xhtml / css
    By Sammie in forum Webdesign / HTML
    Replies: 6
    Last Post: May 30th, 2008, 08:56
  3. xHTML / CSS help
    By Sammie in forum Webdesign / HTML
    Replies: 4
    Last Post: April 5th, 2008, 21:32
  4. Need a Coder (PSD to XHTML/CSS)
    By Andrej in forum Ads & Offers
    Replies: 3
    Last Post: August 25th, 2007, 17:54
  5. erm.. what is XHTML..?
    By dragonash in forum Webdesign / HTML
    Replies: 7
    Last Post: December 31st, 2000, 05:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts