Page 1 of 1

Is XHTML always the right solution?

Posted: Tue Aug 30, 2005 11:10 am
by Woudloper
Sometimes I see different people talking about XHTML and say that this is the best solution to use for a new website. This is not always correct, as there are also some limitations/remarks for XHTML. See for example some of the below mentioned links. XHTML is scricter than HTML, but not always correct when e.g. a WYSIWYG editor (or some other module) does not output XHTML.

Reference: Some quote out one of the above articles:
On the current web, XHTML doesn't have that many advantages over HTML. Some people think that it hasn't got any advantage over HTML, 'cause the correct content-type for XHTML, application/xhtml+xml, isn't supported by Internet Explorer (how many times I have written that sentence...).
The problem is that when you send your XHTML syntax based documents as text/html they will be treated as HTML by the browser. Let me rephrase that: all your documents are handled as tag soup by the browser because they contain invalid HTML. Yes I said HTML. XHTML is a XML based language and should be used and treated as such.

Source: XHTML is invalid HTML
How do the other developers/people think about the relation of XHTML and HTML and do you also have some good resources...

Re: Is XHTML always the right solution?

Posted: Tue Aug 30, 2005 2:00 pm
by trick
Quite true, I belive that of the web authors who say they're using xhtml, maby about 1% of them actually do. This can screw up somethings because it is non standard (for example, the PHP DOM extention goes all funny when you include something like "xmlns='http://w3.org/1999/xhtml'" in anything that's not sent as application/xml or application/xml+xhtml). It is important to remmeber that XHTML is XML that looks like HTML, not HTML that looks like XML.

On the other hand, I admire the attempt by people to at least predend to use XHTML. In fact there are few people who only server XHTML because our well hated browser, Internet Explorer, has no clue how to handle it. If there is a good reason to switch to real XHTML (like firefox gains good SVG support), it will make it easier. CMS may not be ready to properly serve XHTML yet (it might, I haven't checked the source code), but it's a lot more likely than if we were still using HTML 4.x.

btw, here's a good script for sending the good browsers XHTML, and the bad ones HTML:

';?>



Re: Is XHTML always the right solution?

Posted: Tue Aug 30, 2005 3:07 pm
by Ted
CMS itself should be able to send the xhtml mime type.  The problem is that I don't have any control over the content or templates that people enter.  So, I could change it, but it might just blow up when it reaches a good browser.

I'm in the camp where xhtml coding is a good practice to get into now.  It's just more legible and is better for the future.

It's like recycling cardboard or plastic.  You're not really doing a lot for the overall environment by yourself, but it's all about the principle of what will happen when everyone does it.

Re: Is XHTML always the right solution?

Posted: Tue Sep 06, 2005 11:43 am
by trick
I'm just curious. How easy would it be to change the default mime type?

Re: Is XHTML always the right solution?

Posted: Tue Sep 06, 2005 2:57 pm
by Ted
It's defined in lib/classes/class.global.inc.php.

Code: Select all

$this->variables['content-type'] = 'text/html';

Re: Is XHTML always the right solution?

Posted: Mon May 07, 2007 10:42 am
by EffectiveSites
I've just spent some time researching this and came across this post. These are the conclusions I came to:
  • There doesn’t seem to be any major benefit to using XHTML - I accept that it is best practice but the potential problems at the moment outweigh this.
  • It seems better to use HTML strict than use XHTML with the incorrect mime type (i.e. text/html rather than application/xhtml-xml). XHTML with the text/html MIME type are treated as HTML in any case and this practice can cause problems. ( see Sending XHTML as text/html Considered Harmful  http://hixie.ch/advocacy/xhtml
  • If using XTML I would need to use PHP code that would serve the webpage differently depending on the browser:
    - Application/xhtml+xml to browsers that support it i.e. Mozilla
    - Text/html – to browsers that do not support XHTML correctly including IE6.
  • There would be quite a number of changes necessary to write correct XHTML e.g. escape style and script code. See article on ( see Sending XHTML as text/html Considered Harmful  http://hixie.ch/advocacy/xhtml
  • The overriding concern though is the code that would be produced by the content editor in CMSMS when I hand over the website - at the moment I don't think the code produced by CMSMS would be strict XHTML -i.e. code that would work correctly if sent with the correct MIME type application/xhtml+xml. So basically the editor could change some content and even if there was a simple error in the code e.g. a trailing / missing it would give them lots of errors and would not work at all

Here are a few other articles I found:
Beware of XHTML: http://www.webdevout.net/articles/beware-of-xhtml
XHTML Whats the point: http://hsivonen.iki.fi/xhtml-the-point/
XHTML and MIME Types: http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html
Are we sending the wrong MIME type: http://forum.cmsmadesimple.org/index.php/topic,5804.msg31871.html#msg31871

What I've decided to do is use HTML so I've changed the Doctype in my template and use this code which I found on this forum (http://forum.cmsmadesimple.org/index.php/topic,11639.msg58901.html#msg58901 to remove trailing slashes:

Code: Select all

global $html;
$html =  str_replace(' />','>',$params['content']);

Re: Is XHTML always the right solution?

Posted: Mon May 07, 2007 3:54 pm
by Pierre M.
Hello all !
Ted wrote: ...I'm in the camp where xhtml coding is a good practice to get into now...
So do I.
EffectiveSites wrote: If using XTML I would need to use PHP code that would serve the webpage differently depending on the browser:
- Application/xhtml+xml to browsers that support it i.e. Mozilla
- Text/html to browsers that do not support XHTML correctly including IE6.
This is one way to do it, I beg to differ : As this is HTTP related and not specific to CMSms, it should be donne at the webserver level. Webservers have been rewriting HTTP headers to buggy browsers for years.

Pierre M.