Skip to content Skip to sidebar Skip to footer

How To Parse Xml With Special Character? Specifically For Ampersand

I am getting data from text box and change it into xml format and store it in data base. For allowing special characters i wrote javascript function to replace special character wi

Solution 1:

Start with replacing the & character, then replace the other characters. Otherwise you will replace & from the previous entities (< etc.) by &

string.replace(/&/g, '&amp;amp;') //<= start with
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;')
      .replace(/"/g, '&quot;')
      .replace(/'/g, '&apos');
// &apos; may be "\\'",  depends on how te OP wants to use it

[edit based on comments] use &amp;amp; to replace the ampersand character


Post a Comment for "How To Parse Xml With Special Character? Specifically For Ampersand"