tags:

views:

159

answers:

1

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... Anyone can confirm it? Why it has been removed? Replaced by something else?

Sample to validate:

<script type="text/javascript" xml:space="preserve">
    // <![CDATA[
    alert('foo');
    alert('bar');
    // ]]>
</script>
+2  A: 

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.

bobince
Great answer, exactly what I've been looking for (would have voted up if I could)! I found out this issue by upgrading a page from XHTML 1.0 to 1.1 and got this validation error. I can now just remove xml:space from my markup since it's FIXED to preserve in 1.1 (would have been an issue I guess if I have something else than preserve somewhere but that's not the case).
AlexV