Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>JavaScript comes with a powerful <code>replace()</code> method for string objects.</p> <p>In general - and basic - terms, it works this way:</p> <pre><code>var myString = yourString.replace([regular expression or simple string], [replacement string]); </code></pre> <p>The first argument to <code>.replace()</code> method is the portion of the original string that you wish to replace. It can be represented by either a plain string object (even literal) or a regular expression.</p> <p>The regular expression is obviously the most powerful way to select a substring.</p> <p>The second argument is the string object (even literal) that you want to provide as a replacement.</p> <p>In your case, the replacement operation should look as follows:</p> <pre><code>xmlData=xmlData.replace(/&amp;/g,"&amp;amp;"); xmlData=xmlData.replace(/&gt;/g,"&amp;gt;"); //this time it should work. </code></pre> <p>Notice the first replacement operation is the ampersand, as if you should try to replace it later you would screw up pre-existing well-quoted entities for sure, just as <code>"&amp;amp;gt;"</code>. </p> <p>In addition, pay attention to the regex 'g' flag, as with it the replacement will take place all throughout your text, not only on the first match. </p> <p>I used regular expressions, but for simple replacements like these also plain strings would be a perfect fit.</p> <p>You can find a complete reference for <code>String.replace()</code> <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace" rel="nofollow">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload