Skip to content

Escaping

The following characters have a special meaning in an XML document, because they are used to describe the document structure. If one wants to use one of them in an XML document as part of text or an attribut value, one has to sometimes replace them with an escape sequence.

Character Escape sequence Escaping required?
< &lt; Always
> &gt; Never
" &quot; Only in attributes with "
' &apos; Only in attributes with '
& &amp; Always

The escape sequences are described in the XML 1.0 specification. If one does not want to memorize when a particular character is required to be escaped, one can always escape the five listed characters.

Example

<p>
  The symbol <code>&lt;</code> stands for <quote>less than</quote>.
</p>

An alternative to escape sequences is the use of CDATA sections.