XHTML 1.1 and xml:space attribute for script tag
In XHTML 1.0, using the xml:space attribute in a tag is valid, but in XHTML 1.1 it is not valid (using the same markup).
I can't find it in the docs...can anyone confirm it? Why has it been removed? Has it been replaced by something else?
Sample to validate:
<script type="text/javascript" xml:spac开发者_如何转开发e="preserve">
// <![CDATA[
alert('foo');
alert('bar');
// ]]>
</script>
In XHTML 1.1 xml:space
has a fixed value of preserve
on all elements, including <script>
, according to http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod:
<!ATTLIST %script.qname;
xml:space ( preserve ) #FIXED 'preserve'
as such I don't believe it should be an error to declare xml:space="preserve"
on the <script>
element, and I don't know why the validator is tripping on it.
However, by the same token, there is nothing whatsoever to be gained by including the attribute. I'm not sure what you're hoping to achieve by it... the ‘default white-space processing mode’ of all web browsers and general XML tools will preserve whitespace in <script>
in any case.
精彩评论