суботу, 20 лютого 2010 р.

JavaScript: replace XML special characters


XmlHelper = {};

XmlHelper.getExp = function(str)
{
return new RegExp(str, 'g');
}

XmlHelper.encodeInvalidChars = function(str) {
return str
.replace(this.getExp('&'),'&')
.replace(this.getExp('<'),'&lt;')
.replace(this.getExp('>'),'&gt;')
.replace(this.getExp('\''),'&apos;')
.replace(this.getExp('"'),'&quot;')
}
XmlHelper.decodeInvalidChars = function(str) {
return str
.replace(this.getExp('&amp;'),'&')
.replace(this.getExp('&lt;'),'<')
.replace(this.getExp('&gt;'),'>')
.replace(this.getExp('&apos;'),'\'')
.replace(this.getExp('&quot;'),'"')
}

четвер, 18 лютого 2010 р.

C#: replace XML special characters

System.Security.SecurityElement.Escape(string str);


  1. & - &amp;

  2. < - &lt;

  3. > - &gt;

  4. " - &quot;

  5. ' - &apos;