DB2 10.5 for Linux, UNIX, and Windows

Boundary whitespace in direct element constructors

Within a direct element constructor, boundary whitespace is a sequence of consecutive whitespace characters that is delimited at each end either by the start or end of the content, or by a direct constructor, or by an enclosed expression. For example, boundary whitespace might be used in the content of the constructor to separate the end tag of a direct constructor from the start tag of a nested element.

The following diagram shows an example of a direct element constructor, with the boundary whitespace highlighted:

The diagram shows carriage returns and whitespace characters around start and end tags of elements.
The boundary whitespace in this example includes the following characters: a newline character and four space characters that occur between the start tags of the product and description elements; four space characters that occur between the start tag of the description element and the enclosed expression; four space characters that occur between the enclosed expression and the end tag of the description element; and one newline character that appears after the end tag of the description element.

Boundary whitespace does not include any of the following types of whitespace:
  • Whitespace that is generated by an enclosed expression
  • Characters that are generated by character references (for example,  ) or by CDataSections
  • Whitespace characters that are adjacent to a character reference or a CDataSection

The boundary-space policy controls whether boundary whitespace is preserved by element constructors. This policy is specified by a boundary-space declaration in the query prolog. If the boundary-space declaration specifies strip, then boundary whitespace is discarded. If the boundary-space declaration specifies preserve, then boundary whitespace is preserved. If no boundary-space declaration is specified, then the default behavior is to strip boundary whitespace during element construction.

Examples

  • In the following example, the constructed cat element node has two child element nodes that are named breed and color:
    <cat>
      <breed>{$b}</breed>
      <color>{$c}</color>
    </cat>
    Because the boundary-space policy is strip by default, the whitespace that surrounds the child elements will be stripped away by the element constructor.
  • In the following example, the boundary-space policy is strip. This example is equivalent to <a>abc</a>:
    declare boundary-space strip;
    <a> {"abc"} </a>
  • In the following example, however, the boundary-space policy is preserve. This example is equivalent to <a> abc </a>:
    declare boundary-space preserve;
    <a> {"abc"} </a>
    Because the boundary-space policy is preserve, the spaces that appear before and after the enclosed expression will be preserved by the element constructor.
  • In the following example, the whitespace that surrounds the z is not boundary whitespace. The whitespace is always preserved, and this example is equivalent to <a> z abc</a>:
    <a> z {"abc"}</a>
  • In the following example, the whitespace characters that are generated by the character reference and adjacent whitespace characters are preserved, regardless of the boundary-space policy. This example is equivalent to <a> abc</a>:
    <a>     &#x20;{"abc"}</a>
  • In the following example, the whitespace in the enclosed expression is preserved, regardless of the boundary-space policy, because whitespace that is generated by an enclosed expression is never considered to be boundary whitespace. This example is equivalent to <a> </a>:
    <a>{" "}</a>
    The two spaces in the enclosed expression will be preserved by the element constructor and will appear between the start tag and the end tag in the result.