Question

First off, let me say that I know that XHTML isn't really a thing anymore. However, this question is in fact about the web's history. Or rather, how this particular thing managed to become a part of its history.

I had answered this question and later when seeing it was closed as a duplicate of this one I read the answers there too. The mention of the problems it caused in XHTML interested me and I also started wondering just where (if at all) the definitions allowed the html comments. I found that every version of css explicitly allowed html comment tags in its definition. For one thing, this should mean that it should be possible to add them external stylesheets without any trouble. I also found that indeed XHTML 1.0 made the contents of the style and script-tags PCDATA rather than CDATA. I also looked into the consequences these things had.

Now, I don't understand how this could have come to be. I don't see any advantages to this change, while I see a lot of disadvantages:

  1. It made the commenting technique used in scripts and stylesheets cause the script/stylesheet not to be read at all. It's true that that technique was outdated even back then, but it still seems a little extreme to break it like this.

  2. It caused all sorts of trouble with just about any inline javascript, as < and & are two commonly used characters in the language and would generally mean that the xml parser would fail.

  3. Even when trying to solve to solve 2 with the best possible code (//<![CDATA[ and //]]>) you'd still run into problems with some code (code that happened to have ]]> in after it a < or &)

Now I bet there must be something positive about this I missed, or otherwise it wouldn't have ended up in the XHTML standard. Or maybe something strange I didn't think of happened? In other words: How did this end up in the XHTML standard despite all its problems?

Was it helpful?

Solution

Quite simply, it is required by the XML parsing rules. Whereas HTML has all manner of different parsing rules for different elements, and is therefore only good for the HTML vocabulary, XML has a consistent system that can be used for any vocabulary, of which XHTML is just one. The cost of that is character data cannot allow unescaped < or & characters in any element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top