SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    serving a document in different mime types?

    I'm trying to learn about serving a page as text/html or application/xhtml+xml.... Where is this distinction made? On a server setting? In the meta element's content attribute?

    I'm not even sure I'm using the right terminology here..

    I really don't understand this aspect of mark up at all. I found articles online that say serving xhtml as text/html is bad and it lists reasons, but I'm pretty sure I do that and my pages look the way I want, tested in a number of browsers (with some css tweaking of course).

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,447
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Browsers do several things when determining how to render a page. They look at the Content-type header. The <!DOCTYPE and to a lesser extent, <meta http-equiv='Content-Type'
    If things don't "jive", the browser may render the page in "quirks" or "almost standards" mode (doctype switching), which may not be what you wanted.

    AFAIK, most servers serve php and html pages as text/html, but if you have PHP you can send a Content-type header().

    Note IE (>=6 anyway) doesn't recognize the application/xhtml+xml header and won't render the page.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike View Post
    I'm trying to learn about serving a page as text/html or application/xhtml+xml.... Where is this distinction made? On a server setting?
    See How do I serve XHTML with the proper MIME type? in the XHTML vs HTML FAQ.

    You need to make the server send the proper Content-Type header, or use a server-side scripting language and send it yourself.

    Quote Originally Posted by tictike View Post
    In the meta element's content attribute?
    No, that won't work. A user agent must know the content type before it starts parsing the document. In the case of HTML vs XHTML, a browser needs to know if it should use its HTML parser or its XML parser. They are very different.

    Quote Originally Posted by tictike View Post
    I really don't understand this aspect of mark up at all.
    It's not to do with markup as such, really. The content type is something you need to tell the recipient about whenever you serve a resource via HTTP. A browser or other user agent needs to know whether it's about to get an HTML document, an X(HT)ML document, a PNG image, a plain text file, an Excel spreadsheet, or whatever. And it needs to know this before it can make a decision about what to do with that resource.

    Quote Originally Posted by tictike View Post
    I found articles online that say serving xhtml as text/html is bad and it lists reasons, but I'm pretty sure I do that and my pages look the way I want, tested in a number of browsers (with some css tweaking of course).
    It may or may not be 'bad'. The thing is that if you serve XHTML markup – or anything else, including a Word document or a JPEG image – as text/html, user agents are required to interpret it as HTML. In other words, you're not using XHTML at all if you do this.

    The page may look the way you want (thanks to browser bugs and error handling), but it's not XHTML and you can't use any features that XHTML offers over HTML.

    While it's considered okay (albeit pointless) to serve a subset of XHTML as text/html, it's important to understand that the document must still work if served as an application of XML. If you aren't aware of the fundamental differences between these two markup languages, chances are that it won't.

    I recommend that you read the XHTML vs HTML FAQ thoroughly.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a feeling the syntax differences aren't the fundamental difference you're talking about. I'll read the FAQs thoroughly and probably post some other questions.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,447
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    This Opera page lists some differences in how pages are rendered http://www.opera.com/docs/specs/doctype/ and has links to Microsoft and Mozilla documentation.
    • CSS size and position properties specified without a unit
    • CSS size and position properties with a space between the number and the unit
    • CSS class and ID selectors starting with a number
    • The 'height' attribute in table rows (7.0-7.11)
    • Vertical overflow in block elements with a specified height
    • CSS properties are inherited into tables in Standards Mode
    • Inline elements with a specified width are replaced by an inline block in Quirks Mode
    • CSS font sizes are increased by one in quirks mode compared to Standards mode
    • Opera is case-sensitive for CSS class and ID selectors in Standards mode
    • Box-sizing is based on the IE/Windows border-box model in quirks mode
    • The margins of the containing box are subtracted when computing percentage widths

  6. #6
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I read through XHTML vs. HTML FAQs and there's one concept I'm hoping you can clear up for me.

    In the question 'Do I need the xmlns attribute in my <html> tag?' it says, 'Yes. That is what tells user agents that the document is, in fact, XHTML..'

    In the next FAQ 'How does this MIME type thingy work?', I think I'm reading that the MIME type of the Content-Type header determines a real xhtml document or not.

    So..these work together to serve a real xhtml document?

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike View Post
    In the question 'Do I need the xmlns attribute in my <html> tag?' it says, 'Yes. That is what tells user agents that the document is, in fact, XHTML..'

    In the next FAQ 'How does this MIME type thingy work?', I think I'm reading that the MIME type of the Content-Type header determines a real xhtml document or not.

    So..these work together to serve a real xhtml document?
    Yes. Content-Type: application/xhtml+xml says that the document is an application of XML, nothing more. The XML namespace declaration is what tells user agents that this particular flavour of XML is XHTML.

    You may also declare the MIME type as application/xml or text/xml. As long as you've got the right XML namespace declaration it will be recognised as XHTML.

    With the right MIME type but no namespace declaration, you get generic XML.
    The XML namespace declaration only makes sense if the MIME type says it's XML.

    You need both to make it real XHTML. Funny enough, the doctype declaration has nothing to do with it.
    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
  •