Whitespace handling varies by implementation and depends on whether the implementation uses schema validation, and how it chooses to handle whitespace in element content. Every XML parser normalizes the whitespace in attribute values, replacing carriage returns, line feeds, and tabs with spaces. XML Schema processors may further normalize whitespace of an attribute or element value based on its type. During XML Schema validation, whitespace is preserved in values of type xs:string
(and some of its descendants), but collapsed in all others.
Within string literals in queries, whitespace is always significant. For example, the expression string-length(" x ")
evaluates to 3
, not 1
.
The normalize-space
function collapses whitespace in a string. Specifically, it performs the following steps:
Replaces each carriage return (#xD
), line feed (#xA
), and tab (#x9
) character with a single space (#x20
)
Collapses all consecutive spaces into a single space
Removes all leading and trailing spaces
Table 17-11 shows some examples.
3.139.82.4