XML attribute value normalization

I am reading the XML specification in W3C, and this part of the section in normalizing the attribute value caught my attention:

If the attribute type is not CDATA, then the XML processor MUST continue to process the normalized attribute value, discarding leading and trailing spaces (# x20) and replacing whitespace (# x20) with one space (# x20).

Does this mean that

<tag attr=" a      b " />

equivalently

<tag attr="a b" />

Or am I misinterpreting what the spec says?

+3
source share
2 answers

Your interpretation is correct, given that the type "attr" is not CDATA, but most likely it is.

XML : http://www.xml.com/axml/testaxml.htm

+4

, @Per Norrman (+1) , .

<!DOCTYPE tag [
<!ELEMENT tag EMPTY>
<!ATTLIST tag
          attr NMTOKENS #IMPLIED>
]>
<tag attr=" a      b "/>

<!DOCTYPE tag [
<!ELEMENT tag EMPTY>
<!ATTLIST tag
          attr NMTOKENS #IMPLIED>
]>
<tag attr="a b"/>

attr NMTOKENS ( ).

NMTOKEN, attr - (CDATA = ):

<!DOCTYPE tag [
<!ELEMENT tag EMPTY>
<!ATTLIST tag
          attr CDATA #IMPLIED>
]>
<tag attr=" a      b "/>

, attr - CDATA.

+2

All Articles