Click to See Complete Forum and Search --> : entity issues... &, >, <

04-30-2001, 01:50 PM
I have an *.asp page form that I parse out to XML. Problem is... people can put into the fields &, <, and >. Those need to be &amp;, &lt;, and &gt;.

I was thinking of using a simple JavaScript that would validate and replace those values (I got a question for that in Scripting and Backend) but is there a way within the XML to allow those values within (CDATA) strings? Is there anyway to add a rule where those values, as long as they are within double-quotes - thus a string - it knows that & really equals &amp;?

...yepo, need some help on this one...

04-30-2001, 08:51 PM

I've had the same problem. I came up with this solution. It's a little messy with 2 functions but always works.

escape(<&tag>&<<>>>"No Problem");

function escape_str(str){

var munch = ['&','<','>','"'];
var repl = ['&#38;','&#60;','&#62;','&#34;']
var arrayLen = munch.length;

for(var i=0;i<arrayLen;i++){
str = escape_strSub1 (munch[i],repl[i],str);
return str;
function escape_strSub1(char,repl,str){

var clear;
var arr = str.split(char);
clear = arr.join(repl);
return clear;