SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XHTML 1.0 Strict DOCTYPE Question

    Here is my code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Web Page</title>
    </head>
    <body>
    <p><center>Text</center></p>
    <p>Text</p>
    </body>
    </html>

    When I view it in Internet Explore it correctly centers the word text. Why does it show up this way? The DOCTYPE shouldn't support it.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Browsers don't use DOCTYPE declarations that way. They support the <center> element, so it works in Strict even though it's not declared in that DTD.

    Browsers only look at the DTD to determine whether to render the document in standards mode or in quirks mode (for documents served as text/html; for XML documents they always use standards mode).

    BTW, if you're using an XHTML doctype declaration, you must specify the XHTML namespace in the root tag:
    HTML Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you'r saying that browsers support elements that are not allowed in strict DOCTYPES? I'm just really confused about this. Is there a website that could explain Standard and Quirks mode in more detail?

  4. #4
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a list of what you can use with (X)HTML Strict. Keep in mind this is not comprehensive, but it is pretty close to what you can use and have your document validate. If an element's attribute has a question mark around it, I'm not 100% sure (I'm doing this from memory) and haven't looked it up to confirm or debunk. I'm sure Tommy can correct any mistakes I make, as they will be my own (and I'm tired to boot).
    Code:
    Shared Attributes
    class, dir, id, lang, tabindex, title
    
    Element Names (and their attributes)
    a [href, name(?), rel, rev, tabindex]
    acronym
    address
    area [alt, coords, href, nohref, shape]
    base [href]
    big
    blockquote
    body
    br
    button [name, type, value]
    caption
    cite
    code
    col [align, span, valign, width]
    colgroup [valign, width]
    dd
    del
    dfn
    div
    dl [compact]
    !DOCTYPE
    dt
    em
    fieldset
    form [accept-charset, acceptcharset?, action, enctype, method, name? target?]
    h1, h2, h3, h4, h5, h6 (these are six header elements, grouped together for simplicty sake)
    head
    hr,
    html
    img [alt, height, ismap, src, usemap, width]
    input [accesskey, alt, checked, disabled, ismap, maxlength, readonly, size, src, tabindex, type, value]
    ins
    isindex [prompt]
    kbd
    label [accesskey, for]
    legend [accesskey]
    li [type, value]
    link [href, media, rel, rev, type]
    map [name]
    meta [content, http-equiv, name]
    noscript
    object [classid, codebase, codetype, data, height, type, width]
    ol [compact]
    option [selected, value]
    p
    param [name, value]
    pre
    q
    s
    samp
    script [defer, src, type]
    select [disabled, multiple, size, tabindex]
    small
    span
    strong
    style [media, type]
    sub
    sup
    table [border, cellpadding, cellspacing, frame?, width]
    tbody [align, valign]
    td [align, colspan, height, rowspan, valign, width]
    textarea [cols, disabled, name?, readonly, rows]
    tfoot [valign]
    th [align, colspan, height, rowspan, valign, width]
    thead [align, valign]
    title
    tr [align, valign]
    tt
    ul [compact, type]
    var
    As for standards and quirks mode, the best places are www.w3.org and www.w3schools.com (no relation to the W3C).

    If you want a valid XHTML 1.0 Strict DOCTYPE, you can use this one. Note that I commited a cardinal sin for the sake of IE users - I not only omitted the XML prologue (or encoding as it's actually called), but I also serve it as text/html rather than application/xml+xhtml. Add the proper encoding and switch how it's served (and use UTF-8 or 16) for true XHTML, and you'll be fine. Your IE users will hate you, but such is life. (You may also have to give each self-closing element a proper closing tag, but like I said earlier, it's late, and my brain is fried... must sleep.)
    HTML Code:
    <!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" lang="en">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="imagetoolbar" content="no" />
    <meta name="keywords" content="Keywords go here" />
    <meta name="description" content="A description of each page goes here." />
    <link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen" />
    </head>
    <body>
    
    </body>
    </html>

  5. #5
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pianoman933
    So you'r saying that browsers support elements that are not allowed in strict DOCTYPES?
    Browsers, generally speaking, support all the element types in all HTML DTDs. They don't stop supporting a particular element type because you declare a doctype that doesn't include it.

    Or, to put it in another way: if a browser supports <center>, it will handle elements of that type. Period. Even if you declare a Strict doctype.

    Browsers don't use validating parsers. They didn't even used to care about the DOCTYPE declaration at all, because it was irrelevant to them. The DOCTYPE declaration was only used by validators, because they need to know against which set of declarations they should check for compliance.

    Nowadays, browsers take a quick peek at the DOCTYPE declaration, but not because they care about with which DTD you claim conformance, but only to make an educated guess as to whether the document is modern or old. If it's judged to be old (from using an incomplete DOCTYPE declaration), they will apply CSS rules somewhat differently, in order to prevent old web pages from rendering badly.

    Quirks mode is only about rendering, not about which element types are supported.

    Quote Originally Posted by Dan Schulz
    the XML prologue (or encoding as it's actually called)
    <nitpicking>
    Actually, it's called the XML declaration:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    It declares the XML version and the character encoding used in the document.
    </nitpicking>
    Birnam wood is come to Dunsinane

  6. #6
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've seen it called three different things (declaration, encoding, and prologue) with prologue getting the vast majority of the publisher's ink (yes, actual ink, not pixels).

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The XML prologue can consist of an XML declaration, a DOCTYPE declaration and processing instructions (PIs). (Plus comments.)

    The XML declaration specifies the XML version, and optionally the character encoding and whether it is a standalone document.

    In other words, the XML prologue can contain the XML declaration (and other stuff). The XML declaration can contain the encoding declaration.

    This is an example of an XML prologue containing an XML declaration, a PI and a DOCTYPE declaration. The XML declaration specifies the encoding.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/css" href="/style.css"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    So if the XML prologue contains nothing but the XML declaration, it isn't incorrect to call it a 'prologue'. But it's a special case. The prologue can contain more than the XML declaration.
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    London
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to validate this page against xhtml1.0, and as this is the first time i've tried creating a valid xhtml page i'm obviously missing something, as it keeps failing with the attached error...

    Code:
    <?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" lang="en">
    
    <head>
    
    	<title>Ideas2Innovations - Home</title>
    
    	<meta name="description" content="ideas2innovations, website development company" />
    	<meta name="keywords" content="ideas2innovations, website, design, development, hampshire, southampton, economy" />
    	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    
    	<link rel="stylesheet" title="Main" href="i2i.css" type="text/css" />
    
    </head>
    
    <body>
    
    <p>Hello World!</p>
    
    </body>
    
    </html>
    Attached Images Attached Images

  9. #9
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your problem is that you are serving this document with a MIME type of text/html, which means it will be interpreted and used as an HTML document. The xmlns attribute is not valid in HTML, since HTML doesn't support XML namespaces.

    Your <meta/> element is pointless, I'm afraid, because you cannot change the content type (MIME type) that way. It has to be sent in the proper HTTP header.

    Your web server is apparently sending Content-Type:text/html, which would override your attempted declaration even if it would otherwise have worked.

    You need to get your web server to send the proper HTTP header as Content-Type:application/xhtml+xml. Some pointers on how to do that can be found in the HTML vs HTML FAQ, but it depends on what web server you're using.
    Birnam wood is come to Dunsinane

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    London
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the reply Autistic, i've read the FAQ, excellently written by the way, I usually find techie docs have a tendency to assume the reader knows it all already, and as i'm pretty much a newbie to XHTML & XML that can be very frustrating, however having read your FAQ I understand the issues far far better now, so many thanks for that.

    I think in hindsight that i'll switch the doc type to HTML 4.01 Strict as my markup is not doing anything clever, and doesn't make use of any of the XML features of XHTML. I think I probably made the same mistake as many people new to some of the more 'allegedly whizzier' aspects of web coding, in that having revisted and subsequently redeveloped a couple of previous sites to work in standards compliant browsers such as Firefox 2.0 and Netscape 8.0, and to a lesser extent IE7, I got carried away and thought it might be nice to 'upgrade' and validate these sites against XHTML 1.0, which based on what the sites are doing really isn't neccessary.

    I'll just stick to producing well formed markup and go with HTML 4.01 Strict.

    Many thanks for your help.

  11. #11
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you did know about application/xhtml+xml, I think you were already far ahead of most authors when it comes to XHTML.

    I think HTML 4.01 Strict is a good choice, if you don't actually need the XML features.
    Birnam wood is come to Dunsinane


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
  •