www.webdeveloper.com
Results 1 to 13 of 13

Thread: XHTML or HTML?

  1. #1
    Join Date
    Sep 2003
    Posts
    78

    XHTML or HTML?

    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?

  2. #2
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    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.

  3. #3
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    Here's a text-only article on the subject that I found at this 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:

    Code:
    <?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:

    Code:
    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).
    Every fight is a food fight when you’re a cannibal.

  4. #4
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,141
    Just out of curiosity what does that snippet of code do. I too use xhtml and was wondering whats its meaning is.

  5. #5
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    If you want to use application/xhtml+xml then you have to have this meta tag (but obviously have your own character encoding):

    Code:
    <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):

    Code:
    <%
    
    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 %>
    Every fight is a food fight when you’re a cannibal.

  6. #6
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    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, and sending xhtml as application/xhtml+xml is only supported by Mozilla and newer versions of opera. (complete list) Also, you have to use a server-side language 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 , "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."
    Last edited by The Cheat; 04-27-2004 at 01:48 AM.

  7. #7
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Originally posted by lavalamp
    Here's the code for PHP:

    Code:
    <?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...
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  8. #8
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    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:
    Code:
    <?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");
    }
    ?>


    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.
    Every fight is a food fight when you’re a cannibal.

  9. #9
    Join Date
    Aug 2003
    Posts
    1,576
    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

  10. #10
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    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.

  11. #11
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    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 ); I was playing around last night and I validated one of the pages that used just
    PHP Code:
    <?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.
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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.

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  13. #13
    Join Date
    Nov 2002
    Location
    XYZZY - UK
    Posts
    1,760
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles