The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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).

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().

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

Originally Posted by tictike

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.

Originally Posted by tictike

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.

Originally Posted by tictike

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.

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.