Escape double quote character in XML Escape double quote character in XML xml xml

Escape double quote character in XML


Here are the common characters which need to be escaped in XML, starting with double quotes:

  1. double quotes (") are escaped to "
  2. ampersand (&) is escaped to &
  3. single quotes (') are escaped to '
  4. less than (<) is escaped to <
  5. greater than (>) is escaped to >


Others have answered in terms of how to handle the specific escaping in this case.

A broader answer is not to try to do it yourself. Use an XML API - there are plenty available for just about every modern programming platform in existence.

XML APIs will handle things like this for you automatically, making it a lot harder to go wrong. Unless you're writing an XML API yourself, you should rarely need to worry about the details like this.