Xml as argument in JS
-
Hey, I have a HTML document with a lot of (random placed) XML -files in a table. Now if a field has more then 100characters I want to open it in a popup (with a button) but! because my XML-files contain quotes and so it gives errors. How can u solve this problem? thx!
-
Hey, I have a HTML document with a lot of (random placed) XML -files in a table. Now if a field has more then 100characters I want to open it in a popup (with a button) but! because my XML-files contain quotes and so it gives errors. How can u solve this problem? thx!
Solution is simple: escape your XML data before showing. Escaping converts " symbols to " sequence. Look at the
escape
function in JS reference.------------------------- Don't worry, be happy :o)
-
Solution is simple: escape your XML data before showing. Escaping converts " symbols to " sequence. Look at the
escape
function in JS reference.------------------------- Don't worry, be happy :o)
-
there is the problem, you cant give quote as parameter in a Javascript And you are saying to escape it with a javascript... thx!
Just looked in MSDN -
escape
isn't that method, sorry... This function helps me:function escapeString(str)
{
var escAmpRegEx = /&/g;
var escLtRegEx = //g;
var quotRegEx = /"/g;
var aposRegEx = /'/g;str = str.replace(escAmpRegEx, "&"); str = str.replace(escLtRegEx, "<"); str = str.replace(escGtRegEx, ">"); str = str.replace(quotRegEx, """); str = str.replace(aposRegEx, "'"); return str;
}
After using it, str will not contail any illegal chars.
------------------------- Don't worry, be happy :o)
-
Just looked in MSDN -
escape
isn't that method, sorry... This function helps me:function escapeString(str)
{
var escAmpRegEx = /&/g;
var escLtRegEx = //g;
var quotRegEx = /"/g;
var aposRegEx = /'/g;str = str.replace(escAmpRegEx, "&"); str = str.replace(escLtRegEx, "<"); str = str.replace(escGtRegEx, ">"); str = str.replace(quotRegEx, """); str = str.replace(aposRegEx, "'"); return str;
}
After using it, str will not contail any illegal chars.
------------------------- Don't worry, be happy :o)