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? |
---|---|---|
< |
< |
Always |
> |
> |
Never |
" |
" |
Only in attributes with " |
' |
' |
Only in attributes with ' |
& |
& |
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.
An alternative to escape sequences is the use of CDATA sections.