xml Building blocks Text


Example

Text is made of all characters outside of any markup (opening element tags, closing element tags, etc).

<?xml version="1.0"?>
<document>
  This is some text and <b>this is some more text</b>.
</document>

The precise XML terminology for text is character data. The XML specification actually uses the word text for the entire XML document, or a parsed entity, because it defines XML at the syntactic level. However some data models such as the XDM (XQuery and XPath Data Model), which represent XML documents as trees, refer to character data as text nodes, such that text is often understood as a synonym for character data in practice.

Character data may not contain a < character -- this would be interpreted as the first character of an opening element tag -- neither can it contain the ]]> character sequence. The appropriate characters must be escaped with an entity reference instead.

<?xml version="1.0"?>
<document>
  It is fine to escape the &lt; character, as well as ]]&gt;.
</document>

For convenience, one can also escape a bigger chunk of text with a CDATA section (but the sequence ]]> is still not allowed for obvious reasons):

<?xml version="1.0"?>
<document>
  <![CDATA[
    In a CDATA section, it is fine to write < or even & and entity references
    such as &amp; are not resolved.
  ]]>
</document>