XML technologies / XML Schema / Using predefined simple data types / Whitespace processing

(Excerpt from “XML Schema” by Eric van der Vlist)

The treatment of certain characters, tab, line feed, carriage return and space, often used to make XML documents look nice, has always been controversial. W3C XML Schema requires a general two-step algorithm applying to most predefined data types, in fact all except two, xs:string and xs:normalizedString.

Whitespace replacement (normalization)

This first processing step applies to the parsed value. Every whitespace occurrence, #x9 (tab), #xA (line feed) and #xD (carriage return), is replaced with a space (#x20), a normalization. The character count is unchanged by this step, applied to all predefined types except xs:string, whose parsed value undergoes no whitespace replacement.

Whitespace collapsing

The second step removes leading and trailing spaces and replaces every uninterrupted run of spaces with one space. It applies to all predefined types except xs:string, whose parsed value undergoes no whitespace replacement, and xs:normalizedString, whose whitespace is only normalized.

This meaning of “normalized string” does not match the XPath function normalize-space(), which corresponds to what W3C XML Schema calls whitespace collapsing. The DOM method normalize() means something else again: merging adjacent text objects.

   

 

 

 

back to top