tags:

views:

30

answers:

1

So I've tried this XHTML 1.1 code (validated at validator.w3.org) in Chrome 6, IE 8, and Firefox 3.5. The <p> following the <a/> gets hyperlinked, and the <p> following the <div/> turns red:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
<html 
xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>test</title>
</head>
<body>
<p><a href="http://www.yahoo.com"/&gt;&lt;/p&gt;
<p>
this should not be hyperlinked
</p>
<div style="background:red"/>
<p>this should not be red</p>
</body>
</html>

This is really bad news for anyone trying to deal with documents using XML parsers/generators.

I might be able to just convert all </> tags to <></>, but that would mean that things like <br/> become <br></br> -- which is just weird, albeit valid.

Thoughts?

+3  A: 

If you serve your document with an XML content-type (such as application/xhtml+xml) then you shouldn't have this problem.

It sounds like you are serving your document as text/html (although this isn't blessed by the text/html specification, which only goes up to XHTML 1.0) in which case you need to follow the HTML compatibility guidelines as you are telling browsers (and other user agents) that it is HTML rather than XHTML.

I might be able to just convert all </> tags to <></>, but that would mean that things like <br/> become <br></br> -- which is just weird, albeit valid.

… and wrong. Some browsers will treat that as <br><br>. Elements defined as EMPTY should use self-closing syntax, everything else should have explicit start and end tags.

Sadly, the simple option of using the correct content-type just introduces a different problem…

Internet Explorer won't open XHTML documents

… although I believe this will be resolved when IE8 and lower lose significant market share as IE9 introduces support for XHTML.

David Dorward
Blahhh well that'll just take forever to happen. I guess I'll have to just convert all the non-empty elements to use the `<></>` syntax. Do you happen to know if that list on that spec is exhaustive?
Rei Miyasaka
Furthermore, to quote Ian Hickson, "There is no spec that allows sending XHTML 1.1 as text/html". Unfortunately this makes it practically unusable for regular web pages, because of the ineptitude of Internet Explorer.
jasso
http://www.w3.org/TR/html4/index/elements.html has an exhaustive list, look for the E column.
David Dorward
Thanks a bunch!
Rei Miyasaka