How to change MIME type to application/xhtml+xml ?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

My blog at http://dieweltistgarnichtso.net/ identifies itself as text/html page. However, that limits me in embedding correct XHTML in posts, since browsers like Firefox parse the site as HTML.

How can i change the given MIME type to application/xhtml+xml ?
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by yellowled »

erlehmann wrote:How can i change the given MIME type to application/xhtml+xml ?
Your template's index.tpl should contain a line like:

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset={$head_charset}" />
However, the Content-Type for html files (as far as I know) is always supposed to be "text/html" - what's your source for this being wrong?

YL
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

yellowled wrote:However, the Content-Type for html files (as far as I know) is always supposed to be "text/html" - what's your source for this being wrong?
I was of the impression that S9Y outputs XHTML. The W3C validator thinks that, too.
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by yellowled »

erlehmann wrote:
yellowled wrote:However, the Content-Type for html files (as far as I know) is always supposed to be "text/html" - what's your source for this being wrong?
I was of the impression that S9Y outputs XHTML. The W3C validator thinks that, too.
Yes, that's true. But that doesn't require changing the Content-Type (again, as far as I know).

It's also true that you get some validation errors for your blog, but that's not very likely because of the different Content-Type but because of some XHTML errors in your posts. Let's see ...

Okay, first of all, your index.tpl is missing an xmlns attribute. In that file, edit the <html> line like this:

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$lang}" lang="{$lang}">
Second, you have some tags in your source code which are not not valid XHTML - i.e. it's <br />, not <br/> (note the white space character). Are you using a WYGIWYS editor? Which one?

YL
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

yellowled wrote:
erlehmann wrote:I was of the impression that S9Y outputs XHTML. The W3C validator thinks that, too.
Yes, that's true. But that doesn't require changing the Content-Type (again, as far as I know).
It does; simply because browsers parse it as HTML otherwise. HTML has no namespace feature and isn't necessarily well-formed, so i can't embed XML, Javascript makes problems, too - in XHTML it must be masked as CDATA. In the end, I like XHTML better, it's simpler for most purposes and hasn't that many quirks.
It's also true that you get some validation errors for your blog, but that's not very likely because of the different Content-Type but because of some XHTML errors in your posts.
I'm working on this. Since the XHTML engine wasn't triggered, I didn't notice it at first.
Second, you have some tags in your source code which are not not valid XHTML - i.e. it's <br />, not <br/> (note the white space character).
How come ? I though both was correct ...
Are you using a WYGIWYS editor? Which one?
Nope, I write code the old-fashioned way.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by garvinhicking »

Hi!

You can emit XHTML with a simple html Content-Type, browser's accept this.

Forcing an xhtml content-type header will make the site unparsable in case an error occurs. A simple "<br>" will lead to the WHOLE SITE not being displayed.

This is the reason why Serendipity does not use XHTML as the content-type.

You can emit that on your own if you edit/create a template'S config.inc.php and use:

Code: Select all

header('Content-Type: application/xhtml+xml; charset=UTF-8');
However, I don't recommend that. No good comes from it.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by yellowled »

erlehmann wrote:
Second, you have some tags in your source code which are not not valid XHTML - i.e. it's <br />, not <br/> (note the white space character).
How come ? I though both was correct ...
I can't really tell you why this is, but it is :) XHTML is much more strict in terms of cases and closing tags correctly.
erlehmann wrote:
Are you using a WYGIWYS editor? Which one?
Nope, I write code the old-fashioned way.
Very good, because in my humble opinion it's the only sane way to go if you want valid XHTML output :)

YL
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

yellowled wrote:
erlehmann wrote:
Second, you have some tags in your source code which are not not valid XHTML - i.e. it's <br />, not <br/> (note the white space character).
How come ? I though both was correct ...
I can't really tell you why this is, but it is :) XHTML is much more strict in terms of cases and closing tags correctly.
W3C validator accepts it, apparently. I also couldn't locate anything in the XHTML spec.
garvinhicking wrote:You can emit XHTML with a simple html Content-Type, browser's accept this.
They accept this as HTML, which means: No namespaces and possibly javascript errors.
Forcing an xhtml content-type header will make the site unparsable in case an error occurs. A simple "<br>" will lead to the WHOLE SITE not being displayed.
I want that behaviour, so I can make my site standards compliant.
This is the reason why Serendipity does not use XHTML as the content-type.
If you'd use it, errors in plugins would be noticed way sooner, wouldn't they ?
However, I don't recommend that. No good comes from it.
Aside of that I will be forced to write correct XHTML, any other problems ?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by garvinhicking »

Hi!
If you'd use it, errors in plugins would be noticed way sooner, wouldn't they ?
Serendipitys Code is not the problem, it can be easily made XHTML compliant.

User Input is the evil thing: Nobody prevents users from typing "<br>" in their boxes, no one prevents them from invalidly nesting Elements. There is no easy way to make sure that the user input on a page is always XHTML valid.
Aside of that I will be forced to write correct XHTML, any other problems ?
I can't really tell, my personal bottom line as always that the application/xhtml+xml was never required. You mentioned that namespaces cannot be used. What exactly do you mean? Which kind of errors do you get, when a document has text/html as content-type instead of application/xhtml+xml, when the content of the document is the same?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

garvinhicking wrote:User Input is the evil thing: Nobody prevents users from typing "<br>" in their boxes, no one prevents them from invalidly nesting Elements. There is no easy way to make sure that the user input on a page is always XHTML valid.
Well, check it against the XHTML DTD on submission ? I do a (simple) web app and we do exactly that - although our DTD is slimmed down to only include semantic elements.
You mentioned that namespaces cannot be used. What exactly do you mean?
XML has Namespaces, HTML hasn't. What is unclear about that ?
Which kind of errors do you get, when a document has text/html as content-type instead of application/xhtml+xml, when the content of the document is the same?
The embedding of Javascript is different between HTML and XHTML - as far as I am aware, user agents have hickups there. for XHTML it is

Code: Select all

<script type="text/javascript">
<![CDATA[
// here be Javascript
]]>
</script>
while for HTML you don't need the CDATA stuff. Konqueror, for example throws up on this and doesn't execute Javascript marked as CDATA.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by garvinhicking »

Hi!
Well, check it against the XHTML DTD on submission ? I do a (simple) web app and we do exactly that - although our DTD is slimmed down to only include semantic elements.
Simple user's don't understand semantics. All they want to do is blog and type. Putting them on validation restrictions is not productive.

Sadly I don't have konqueror at my hands, so I cannot test the CDATA stuff. Other browsers do interpret CDATA with HTML mimetype as well, so I'm not sure who is misbehaving there. IMHO the content-type should always only be a type hint, not a type restriction -the content should matter..?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

garvinhicking wrote:Simple user's don't understand semantics. All they want to do is blog and type. Putting them on validation restrictions is not productive.
Look, those who can't even bother to learn some simple rules should probably not use tools like (X)HTML; it only makes life worse for the rest of us.

XHTML rules are really simple, way simpler than HTML rules. And you say those who want to use it shouldn't abide by that rules ? Well, humanity did well along centuries without markup, then those lazy-asses can too, don't you think so ?
IMHO the content-type should always only be a type hint, not a type restriction -the content should matter..?
So ... what is the browser supposed to do on a page of unclear type ?

A: Parse it as "tag soup" (read: HTML). Ditch XHTML features.
B: Parse it as XHTML. Preserve XHTML features. Markup errors are fatal.

I like the second much more, probably because I know what I am doing. And every (other) markup / programming language requires that to some extent.

Please note the following:

- In XHTML: <![CDATA[...]]> is a CDATA section. In HTML, it's a bogus comment. Actually, XHTML allows the use of CDATA sections, HTML does not.
- XHTML allows non XHTML elements and attributes (in different namespaces) to be used, HTML does not. Actually, HTML permits no external namespaces.


Best Regards, Summer Glau

P.S.: Don't forget to read Ian Hickson's take on the subject matter.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by garvinhicking »

Hi!

I believe the best way for you is to achieve this with a custom template (or plugin, if you prefer) that simply issues the PHP header() call.

As for Serendipity, as long as browsers make a full page fail to render when markup errors occur, it is not good (read: beneficial for the common end-user) to use the xhtml+xml mimetype.

If you prefer a patch to the s9y core to support the selection of the mimetype as a config option, we can gladly integrate this!

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
erlehmann
Regular
Posts: 12
Joined: Mon Jun 23, 2008 7:17 am

Re: How to change MIME type to application/xhtml+xml ?

Post by erlehmann »

garvinhicking wrote:As for Serendipity, as long as browsers make a full page fail to render when markup errors occur, it is not good (read: beneficial for the common end-user) to use the xhtml+xml mimetype.
You should know what the spec says - and for all purposes of rendering a) XHTML with type text/html is actually HTML (see appendix C of the XHTML spec) and b) fail is there because you just can't guess, there are over 9000 possibilities in each case.

Look at XHTMLMIME, which says:
In summary, 'application/xhtml+xml' SHOULD be used for XHTML Family documents, and the use of 'text/html' SHOULD be limited to HTML-compatible XHTML 1.0 documents.
With your stand on the matter, it will never be possible to actually call S9Y output XHTML, simply because XML features cannot be used that way.
If you prefer a patch to the s9y core to support the selection of the mimetype as a config option, we can gladly integrate this!
Would be very nice. Am I expected to write this (i have no idea of S9Ys inner workings - would take a while) or will someone else do (because it probably is only a minor thing) ?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: How to change MIME type to application/xhtml+xml ?

Post by garvinhicking »

Hi!
With your stand on the matter, it will never be possible to actually call S9Y output XHTML, simply because XML features cannot be used that way.
Those pedantic enough that feel the need to do so, can do so with their own templates.

Current templates focus on usability and compatibility instead of pedantic semantics ;)
Would be very nice. Am I expected to write this (i have no idea of S9Ys inner workings - would take a while) or will someone else do (because it probably is only a minor thing) ?
No one expects this of you! To me personally, the matter is not interesting yet because of the choking browser behavior on non-validating XHTML documents. I'm all for "ultra liberal HTML parsing". ;)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply