Why did XHTML have PCDATA inside script and style tags?

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:

  • 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.

  • 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.

  • 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?


    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.

    链接地址: http://www.djcxy.com/p/88782.html

    上一篇: 在表格中的特定行周围边框?

    下一篇: 为什么XHTML在脚本和样式标签中有PCDATA?