SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 70
  1. #1
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic xHTML document structures

    I've been wondering, what's the most basic (and most professional) and up to date standard xHTML document structure? the one i've been using so far is:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="language" content="en-us" />
    </head>
    
    <body>
    </body>
    </html>
    and w3schools.com suggests this:
    Code:
    <!DOCTYPE Doctype goes here>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Title goes here</title>
    </head>
    
    <body>
    Body text goes here
    </body>
    
    </html>
    I've also seen ones that use an xml tag before the doctype, while others defined the language of the document as an attribute in the body (or head, i don't remember exactly) tag.

    So what's the best basic structure in your opinion? and why?

  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)
    This all depends on whether you actually use XHTML or if you're just pretending to by serving it as text/html.

    For real XHTML, it should be something like this:
    HTML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/css" href="/style.css" media="screen,projection"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
      <head>
        <title>Title</title>
      </head>
      <body>
      </body>
    </html>
    Last edited by AutisticCuckoo; Dec 21, 2005 at 23:23.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Addict Sojan80's Avatar
    Join Date
    May 2002
    Location
    Central WI, US
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there some sort of application="xml+html" with XHTML also or is that covered by the <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> posted by Artistic Cuckoo?

  4. #4
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    This all depends on whether you actually use XHTML or if you're just pretending to by serving it as text/html.

    For real XHTML, it should be something like this:
    HTML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/css" href="/style.css" media="screen,projection"?>
    <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
      <head>
        <title>Title</title>
      </head>
      <body>
      </body>
    </html>
    I don't clearly understand what you mean. Will you elaborate more please? what's the difference between the code you posted and the one i posted?

  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 Sojan80
    Isn't there some sort of application="xml+html" with XHTML also or is that covered by the <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> posted by Artistic Cuckoo?
    Those are two very different things.

    The application/xhtml+xml MIME type (sent in the Content-Type HTTP header) tells the browser that the document that follows is an application of XML. You can also use application/xml or, although not recommended, text/xml. Most purported XHTML documents are served with a MIME type of text/html, which means that they are to be considered as HTML documents. With such a MIME type, you are not using XHTML as far as browsers are concerned; you are using badly written HTML.

    The XML namespace declaration in the <html> tag is what tells user agents that it is XHTML (rather than any other application of XML). You must use one of the three aforementioned XML MIME types, or user agents will ignore the XML namespace. If, for instance, you serve your document as text/html, the namespace is ignored, since HTML does not support XML namespaces.

    Quote Originally Posted by mPeror
    I don't clearly understand what you mean. Will you elaborate more please? what's the difference between the code you posted and the one i posted?
    There are three differences:
    1. I use an XML declaration (the first line) that states the character encoding, whereas you use a meta element. Both will be overridden by an encoding specified in an HTTP header, but the XML declaration is the proper way to specify the encoding for X(HT)ML documents. A real XHTML document will ignore your meta element.
    2. I specify the style sheet in the XML prologue. You didn't specify any at all, but I assume you would use a link or style element as in HTML. That still works, but using the XML prologue is more appropriate for X(HT)ML, IMHO.
    3. I didn't use any meta element with a Content-Type HTTP equivalent, because those are ignored for real XHTML anyway.
    Birnam wood is come to Dunsinane

  6. #6
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    There are three differences:
    1. I use an XML declaration (the first line) that states the character encoding, whereas you use a meta element. Both will be overridden by an encoding specified in an HTTP header, but the XML declaration is the proper way to specify the encoding for X(HT)ML documents. A real XHTML document will ignore your meta element.
    2. I specify the style sheet in the XML prologue. You didn't specify any at all, but I assume you would use a link or style element as in HTML. That still works, but using the XML prologue is more appropriate for X(HT)ML, IMHO.
    3. I didn't use any meta element with a Content-Type HTTP equivalent, because those are ignored for real XHTML anyway.
    Do these three differeces really matter? in other words, is my document structure considred "bad xHTML" or what exactly? I'm asking this because i've never seen any xHTML coder using your version.

  7. #7
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use anything other than UTF-8 or UTF-16, and don't specify encoding information with HTTP, then you must have an XML declaration specifying the encoding used.
    Simon Pieters

  8. #8
    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 mPeror
    Do these three differeces really matter? in other words,
    As Simon said, the encoding thing may matter if the web server isn't sending any encoding information in the Content-Type header. XML is supposed to be a self-describing format, so some argue that the server shouldn't send the encoding, in which case the XML declaration is required for anything other than UTF-8 or UTF-16, and recommended in either case.

    The only reason for omitting the XML declaration is if you're using pretend-XHTML, since some old HTML-only browsers have problems with it and IE/Win jumps into quirks mode if it's present. (But if you need to cater for those, you shouldn't use XHTML to begin with.)

    Quote Originally Posted by mPeror
    is my document structure considred "bad xHTML" or what exactly?
    No, although the meta element will indicate that you may not know exactly what you're doing (but only to the handful of people who understand real XHTML).

    Quote Originally Posted by mPeror
    I'm asking this because i've never seen any xHTML coder using your version.
    That's probably because most 'XHTML' coders don't know the first thing about XHTML. They think it's only about using lowercase, sprinkling a few slashes throughout the markup, and – at best – quoting attribute values. They're the ones who'll tell you that XHTML requires a space before the '/>' at the end of a self-closing tag.
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i get it now, thanks for the info. And i was one of those 'XHTML coders' before reading your post btw

    One more thing though: what do i call my document if it just follow the xHTML syntax rules (lowercase, slashes..etc) and doesn't include XML stuff?

  10. #10
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    Is an pragmatic answer not more appropriate, use HTML 4.01 + CSS 2.00, Validate, and use a DTD that gets IE in the same box model as FF NS Moz OP

  11. #11
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mPeror
    One more thing though: what do i call my document if it just follow the xHTML syntax rules (lowercase, slashes..etc) and doesn't include XML stuff?
    Any of the following:
    • XHTML-P, for XHTML Pretend (I think Tommy came up with this one ).
    • Appendix C XHTML, i.e. XHTML following the "HTML Compability Guidelines" from the spec.
    • XHTML as text/html.
    • Invalid HTML.
    Simon Pieters

  12. #12
    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 mPeror
    One more thing though: what do i call my document if it just follow the xHTML syntax rules (lowercase, slashes..etc) and doesn't include XML stuff?
    It depends. If you're serving your documents as application/xhtml+xml, you could call them 'HTML-like XHTML'. If you're serving them as text/html there is only one name for it: HTML. (Badly written, or even invalid.)

    The problem here is that the markup itself may well be perfectly valid, semantic XHTML. But as soon as you serve it as text/html, the document becomes HTML, because user agents must treat it as such. Without digressing into quantum physics, there is a duality about this; it can be XHTML or HTML depending on when you are observing it. Schrödinger would probably have a field day with this, and perhaps spare the poor cat.
    Birnam wood is come to Dunsinane

  13. #13
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    I like to see a website (one page ?) in Real Xhtml
    That runs in the major browser (IE that is), Please

    http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html

  14. #14
    Non-Member lostseed's Avatar
    Join Date
    Sep 2005
    Location
    Zurconion Soon!
    Posts
    1,549
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You always need a DTD, w3schools is probably slacking

  15. #15
    Non-Member
    Join Date
    Jan 2005
    Location
    Netherlands
    Posts
    4,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    Why do you Swedish time wasters not tell that IE is not playing Ball browser wise ?

  16. #16
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Swedish time wasters?

    I've lost count on how many times I've told beginners that XHTML is virtually useless, since it is not supported by IE at all. I've blogged about it again and again. I've said it numerous times in posts here at Sitepoint.

    If you can't be bothered to look, you shouldn't bother to write rude posts either.

    BTW, you can use XHTML with IE ... sort of. If you serve the document with a MIME type of application/xml, IE will recognise it as XML. It still doesn't understand the XHTML namespace, so it will be treated as generic XML. That means you'll have to add a lot of extra CSS rules (like display:block for all block-level elements), but it will work as an XML document.
    Birnam wood is come to Dunsinane

  17. #17
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been using the "HTML like"-xHTML for a long time now, and it's syntax rules is much better. I don't like uppercase tags, attributes without quotes (they're not required in HTML4, are they?) and not closing tags like <img> in HTML4. HTML is just ugly and tiresome to me.

    So is there anyway i can follow xHTML syntax rules while keeping my document perfectly valid?

  18. #18
    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 mPeror
    I don't like uppercase tags
    HTML is case-insensitive, so you can use lowercase if you like. Most modern HTML authors do, I think. I know I do.

    Quote Originally Posted by mPeror
    attributes without quotes (they're not required in HTML4, are they?)
    Not always, but you are recommended to use them at all times. It's much easier than trying to remember when they're required or not.

    Quote Originally Posted by mPeror
    and not closing tags like <img>
    If that single slash really means that much to you, I guess you'd better stick to 'XHTML'.

    Quote Originally Posted by mPeror
    HTML is just ugly and tiresome to me.
    With the exception of the self-closing tags (and let's be honest, there are very few empty element types anyway) and the XML namespace declaration, you can write HTML 4.01 that looks exactly like the pretend-XHTML that most 'XHTML' authors use.
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
      <head>
        <title>Document Title</title>
      </head>
      <body>
        <p>You can't tell whether this is HTML or XHTML without looking closely at the first two lines.</p>
      </body>
    </html>
    Quote Originally Posted by mPeror
    So is there anyway i can follow xHTML syntax rules while keeping my document perfectly valid?
    Valid XHTML, yes. HTML no.
    Last edited by AutisticCuckoo; Dec 21, 2005 at 23:19.
    Birnam wood is come to Dunsinane

  19. #19
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    HTML Code:
    <!DOCTYPE html "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    While I normally don't care much about whether a doctype declaration is valid or not, this one actually triggers quirks mode in Gecko and WebCore.
    Simon Pieters

  20. #20
    SitePoint Addict Sojan80's Avatar
    Join Date
    May 2002
    Location
    Central WI, US
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    This all depends on whether you actually use XHTML or if you're just pretending to by serving it as text/html.

    For real XHTML, it should be something like this:
    HTML Code:
    <?xml version="1.0" encoding="utf-8"?>
     <?xml-stylesheet type="text/css" href="/style.css" media="screen,projection"?>
     <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm-strict.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
       <head>
         <title>Title</title>
       </head>
       <body>
       </body>
     </html>
    Above you are using XHTML 1.0 Strict would these same rules apply if you chise to use XHTML 1.0 Transitional instead of strict?

  21. #21
    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 zcorpan
    While I normally don't care much about whether a doctype declaration is valid or not, this one actually triggers quirks mode in Gecko and WebCore.
    So I forgot one little keyword ...
    Thanks for spotting that. I discovered that I'd forgot it in the XHTML example above, too.

    Quote Originally Posted by Sojan80
    Above you are using XHTML 1.0 Strict would these same rules apply if you chise to use XHTML 1.0 Transitional instead of strict?
    As long as you serve the document as an application of XML, it's the same whether you use Strict, Transitional or Frameset. The only difference would be the doctype declaration itself (the public identifier and the system identifier (DTD URI)).

    Just note that there should be a PUBLIC keyword between html and the public identifier, which I managed to forget when typing the example.
    Birnam wood is come to Dunsinane

  22. #22
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, i read the element specifications and missed the "in" in sensitive.

    So how about the document language and character set in an HTML4 document? should i declare them using meta tags? or is there any more "updated" way to do it?
    example :
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="language" content="en-us" />

  23. #23
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those should be sent by the web server, as a true HTTP header, preferably.
    If they are, the meta elements are ignored.

    You should always specify the primary language with a lang attribute in the <html> tag (xml:lang for real XHTML, both for pretend-XHTML).
    HTML Code:
    <html lang="en">
    Birnam wood is come to Dunsinane

  24. #24
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Hmm "Swedish Time waster" that's a new one? I think he meant "time saver". You should put it in the: <?xml version="1.0" encoding="utf-8"?> for XHTML and with HTML you don't have <meta /> but otherwise that is one way.

  25. #25
    SitePoint Addict RamsayX's Avatar
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so basically if you're not using XML at all on a page, but just HTML content, you shouldn't use XHTML? I'm like the above people who have been using XHTML because the code is much cleaner and structured nicely. I also always validate, using the W3C validator. Using HTML 4.01 Strict, does the code need to be structured the same? Lowercase tags, self-closing tags, etc ... ?

    Like a lot of people, I'm probably one of those who got into XHTML because we heard all about it and read some tutorials that encouraged the practice because it was all the rage. But I thought XHTML was a good thing? It stopped all the sloppy coding that HTML was so forgiving to (the browsers that is, not HTML). Thats why I made the transition to XHTML. Now you're saying that was all a waste of time?

    So to put it very bluntly, if theres no XML being used on a page (which I don't have because I haven't learned XML yet, its on my list of many things to study) ALWAYS use HTML 4.01 strict? I don't see the point of html transitional ...

    As a side point, I would like to understand why I've never had a page get destroyed by IE, my pages always validated, and I always checked for cross-browser compatibility, starting with Gecko and IE. I've seen these examples of pages that IE would just show the document tree, but thats never happened to me. Is that because I've made sure they validated? I still don't really get that, even though I've been reading about "REAL" XHTML for a couple of weeks now. Its so confusing. But I'm going to be looking for a new web related job next spring so I should really figure this out in case an employer knows about it and asks me, I want and need to understand this issue.

    Two more questions, pages that are using an XML-driven CMS like Movable type, should I use XHTML strict or better yet XHTML 1.1? For example this page I'm doing now: http://ramsaystudios.ca/clients/htbc/ (yes I'm aware of the page layout problems, I'm still working on this page) we might add the Movable type CMS later. Would the current structure work for that? And if we DON't add a CMS, what should that page be changed to? HTML 4.01 Strict?

    One more, how do you actually serve the document as application/xhtml+xml;? I don't understand "using the headers to serve it" thing.

    I hope I don't look too stupid now

    Thanks for your help, mostly to Autistic Cuckoo and anyone else whos a REAL XHTML coder
    Personal Portfolio
    Paul O'B is the CSS god


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
  •