Mega Code Archive

 
Categories / XML Tutorial / Introduction
 

Illegal PCDATA Characters and Escaping Characters

<!--This is not well-formed XML!-->  <comparison>6 is < 7 & 7 > 6</comparison>  You can't put < or & characters into PCDATA.  There are two ways you can get around this: escaping characters, or enclosing text in a CDATA section.  To escape the < or &, you replace any < with &lt; and any & with &amp;.  The previous XML example could be made well formed:  <comparison>6 is &lt; 7 &amp; 7 &gt; 6 </comparison>  &lt; and &amp; are known as entity references.  The following entities are defined in XML:  &amp;    - the & character  &lt;     - the < character  &gt;     - the > character  &apos;   - the ` character  &quot;   - the " character  Other characters can also be escaped by using character references.  These are strings such as &#nnn;, where nnn would be replaced by the Unicode number of the character.  Or &#xnnn; with an x preceding the number, where nnn is a hexadecimal representation of the Unicode character. To include the copyright symbol ((c)),  inserting &#169; or &#xA9;.  Entity references must be declared