How can I include an ampersand (&) character in an XML document? How can I include an ampersand (&) character in an XML document? xml xml

How can I include an ampersand (&) character in an XML document?


Use a character reference to represent it: &

See the specification:

The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section.If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.


You can use these escape sequences :

< (less-than)                   -   &#60; or <> (greater-than)                -   &#62; or  >& (ampersand)                   -   &#38;' (apostrophe or single quote)  -   &#39;" (double-quote)                -   &#34;