Search code examples
xmlxml-parsingwhitespacew3c

xml:space="preserve" effect on space between XML attributes?


I know that

<a xml:space="preserve">
<b></b>
</a>

is different than

<a xml:space="preserve">
<b>  </b>
</a>

However, what about

<a xml:space="preserve">
<b c='c'></b>
<c   />
</a>

and

<a xml:space="preserve">
<b     c='c'></b>
<c />
</a>

I can't find documentation about how xml:space="preserve" affects these cases.


Solution

  • The xml:space="preserve" directive says that space within element content is significant.1

    It does not affect whitespace within start tags, which is significant only to the extent that its presence is needed to separate attributes from themselves and from the name of the element:

    [40] STag ::= '<' Name (S Attribute)* S? '>'
    

    Note that the S production requires one whitespace character and allows multiple:

    [3] S ::= (#x20 | #x9 | #xD | #xA)+
    

    1 The default (and only other allowed setting), xml:space="default", allows indentation (pretty-printing) of XML without changing significance.