Let's separately consider unmixed and mixed content:
Unmixed Content
When no text can be mixed between your elements, simply manage whitespace within elements as you wish, and allow XML serializers and editors to manage the whitespace between elements:
<?xml version="1.0" ?>
<nodes>
<node title="root">
<node title="child1">Here is some text for child1.</node>
<node title="child2">Here is some text for child2.</node>
<node title="child3">Here is some text for child3.</node>
</node>
</nodes>
This works fine for both data-oriented and document-oriented XML. (OOXML is an example of document-oriented XML that doesn't need mixed content.)
Mixed Content
When text can be mixed between your elements, decide how to manage whitespace depending upon the semantics of your data. For example, if your data is like HTML, multiple consecutive space mean nothing different than a single space, so allowing XML serializers and editors to manage the whitespace is fine:
<?xml version="1.0" ?>
<nodes>
<node title="root">
<node title="child1">Here is some text for child1. </node>
<node title="child2">Here is some text for child2. </node>
<node title="child3">Here is some text for child3. </node>
Here is some text for root.
</node>
</nodes>
xml:space
If some portion of your XML associates importance to embedded whitespace, you can signify this by adding a special xml:space="preserve"
attribute to the containing element:
2.10 White Space Handling
In editing XML documents, it is often convenient to use "white space"
(spaces, tabs, and blank lines) to set apart the markup for greater
readability. Such white space is typically not intended for inclusion
in the delivered version of the document. On the other hand,
"significant" white space that should be preserved in the delivered
version is common, for example in poetry and source code.
An XML processor must always pass all characters in a document that
are not markup through to the application. A validating XML processor
must also inform the application which of these characters constitute
white space appearing in element content.
A special attribute named xml:space
may be attached to an element to
signal an intention that in that element, white space should be
preserved by applications. In valid documents, this attribute, like
any other, must be declared if it is used. When declared, it must be
given as an enumerated type whose values are one or both of
"default"
and "preserve"
.
You should take care to use xml:space="preserve"
conservatively, however. Placing it on the root element of a complex XML format such as OOXML is likely to make consumers of your data justifiably unhappy.