W3C home > Mailing lists > Public > www-validator@w3.org > May 2009

Re: 1 element becomes 2

From: Michael A. Peters <mpeters@mac.com>
Date: Wed, 20 May 2009 12:58:49 -0700
Message-id: <4A1460F9.20701@mac.com>
To: "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Cc: Hannes Kirsman <hkirsman@gmail.com>, www-validator@w3.org
Jukka K. Korpela wrote:
> Hannes Kirsman wrote:
>> is this a bug of firefox or w3c validator?
> No, it's an error in your document. Technically, it might not be an 
> error (impossible to say without a URL), but in that case it's a matter 
> of your misunderstanding.
>> I have <a href="" /> tag
> Why?
> You should not use XHTML in the first place, unless you really know what 
> you are doing, and 99% of XHTMLers don't.

Just to explain the problem - if your server sends the document with the 
'application/xml+xhtml' mime type, browsers like Internet Explorer will 
not render the document but instead will ask the user what application 
they want to open it with.

OTOH if you send text/html as the mime type, you are not standards 

The way around it is to detect whether or not the browser supports xhtml 
(via the $_SERVER['HTTP_ACCEPT'] header the browser sends to the server) 
before sending the document, and only send the xhtml version of the page 
to browsers that advertise they know what to do with xhtml - sending 
html version of document to browsers that don't.

That generally requires constructing your document with something like 
php's DOMDocument class so that you can fairly easily send the right 
type of document [via saveXML() or saveHTML()] to the requesting browser.

Another problem is that with x(ht)ml, you must make sure there are no 
xml violations or it will not display. Again that is best accomplished 
using an XML class to fully construct the document and then exporting to 
xml when sending to the client.

Yet another problem is that xml doesn't give the latitude in comment 
content. IE -

<script language='javascript'>

often results in invalid xml, you have to use cdata sections instead.

Yet another issue (for some people, not me - I don't use third party 
javascript), if you declare your document to be xhtml, it seriously 
limits the number of third party javascript libraries you can use, 
because most do not conform to DOM2 specification for client side 
dynamic alteration of xhtml.

All that being said, I wish more of the web was xhtml. Until Microsoft 
adds proper xhtml parsing to their browser (not even there in IE8) most 
of the web will remain html.

> Even if you use XHTML, you should not use self-closing tags for anything 
> but elements with EMPTY declared content, as both XML and XHTML specs 
> say. If you didn't understand this, you _surely_ should not use XHTML!

Even with empty content, some (all ??) get it wrong.
<a id='foo' />

is legal valid xhtml but most (all ??) browsers will incorrectly parse 
it, so you have to use
<a id='foo'></a>

Self closing script tags can also be problematic with some browsers.

These are browser bugs, but unfortunately they are bugs you have to deal 
with, and even once fixed, many people rarely update their browsers. I 
still see IE6 quite often and even sometimes Netsape 4 in my server 
logs, and I only run a couple special interest websites.
Received on Wednesday, 20 May 2009 19:59:49 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:59:12 UTC