The xml:space Attribute
The special attribute xml:space
indicates that whitespace should
be preserved as specified in element content.
Example
<message xmlns="http://simonstl.com/ns/examples/message"
xml:space="preserve"
lang="en" date="20051006" >
THIS
IS A
MESSAGE!
</message>
Description
XML processors must always pass all characters that aren’t
markup through to an application. When xml:space
is used on an element with a
value of preserve
, the whitespace
in that element’s content must be preserved as is by the application
that processes it. The whitespace is always passed on to the
processing application, but xml:space
provides the application with a
hint regarding how to process it. Another legal value for xml:space
is default
, which indicates that default
whitespace processing by the application is acceptable (this is the
default behavior in absence of the xml:space
attribute). The attribute and
its value also apply to child elements.
Tip
A validating XML processor must also report whitespace in element-only content (that is, the whitespace between tags in an element that can contain only elements, not character data).
See also
§2.10
Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.