dealing with 'awkward' characters in the XML file

Hi Clifton,
I have been wrestling with a problem and have found a solution but I think there must be a better way to do this and if there is, I'm sure you'll know what it is.
When I started this project (many years ago
) I decided to leave the file system as it had been in the VB version i.e. including names that contain apostrophes and names that contain spaces. Surprisingly this did not cause problems in the code generated by the TB actions system. I guess there must be a few built in safety nets.
I have just transferred a function to the code in the XML file and there these things do cause problems. I am displaying a graphic in a field called "pictureBox" which must be resized and the source file path contains both a space and an apostrophe. I thought encodeURIComponent might help and I then I tried JSON.stringify but neither solved the problem. So I came up with this laborious method which actually works in this case:
<pictureBox>
<function name="myUser" event="user" params="evt,value" useTB="true">
<![CDATA[
//value[0] = width, value[1] = height, value[2] = directory, value[3] = file!!
tbfunction_pgTBObjSet("pictureBox", "width", value[0]);
tbfunction_pgTBObjSet("pictureBox", "height", value[1]);
tbfunction_pgStyleObject("pictureBox", "backgroundSize", value[0] + "px " + value[1] + "px");
//THE LINE BELOW WITH AN ESCAPED APOSTROPHE WORKS BUT IT DOESN'T USE alue[2] + [value[3]:!!
//var address = 'url("../../France1/Mimine\'s_Academy_of_Poo_Studies/teachers/BLOGGS_Bill/ENGLISH/Immagini/P-0 gardening.jpg")';!!
//value[2] + value[3] produces "../../France1/Mimine's_Academy_of_Poo_Studies/teachers/BLOGGS_Bill/ENGLISH/Immagini/P-0 gardening.jpg";!!
var address = value[2] + value[3];
address = tbfunction_pgReplace("'", String.fromCharCode(92) + "'", address)
address = "url(" + String.fromCharCode(34) + address + String.fromCharCode(34) + ")";
tbfunction_pgStyleObject("pictureBox", "background-image", address);
tbfunction_pgTBObjSet("pictureBox", "visible", true);
]]>
</function>
</pictureBox>
Can you suggest a better alternative, please?
John
I have been wrestling with a problem and have found a solution but I think there must be a better way to do this and if there is, I'm sure you'll know what it is.
When I started this project (many years ago

I have just transferred a function to the code in the XML file and there these things do cause problems. I am displaying a graphic in a field called "pictureBox" which must be resized and the source file path contains both a space and an apostrophe. I thought encodeURIComponent might help and I then I tried JSON.stringify but neither solved the problem. So I came up with this laborious method which actually works in this case:
<pictureBox>
<function name="myUser" event="user" params="evt,value" useTB="true">
<![CDATA[
//value[0] = width, value[1] = height, value[2] = directory, value[3] = file!!
tbfunction_pgTBObjSet("pictureBox", "width", value[0]);
tbfunction_pgTBObjSet("pictureBox", "height", value[1]);
tbfunction_pgStyleObject("pictureBox", "backgroundSize", value[0] + "px " + value[1] + "px");
//THE LINE BELOW WITH AN ESCAPED APOSTROPHE WORKS BUT IT DOESN'T USE alue[2] + [value[3]:!!
//var address = 'url("../../France1/Mimine\'s_Academy_of_Poo_Studies/teachers/BLOGGS_Bill/ENGLISH/Immagini/P-0 gardening.jpg")';!!
//value[2] + value[3] produces "../../France1/Mimine's_Academy_of_Poo_Studies/teachers/BLOGGS_Bill/ENGLISH/Immagini/P-0 gardening.jpg";!!
var address = value[2] + value[3];
address = tbfunction_pgReplace("'", String.fromCharCode(92) + "'", address)
address = "url(" + String.fromCharCode(34) + address + String.fromCharCode(34) + ")";
tbfunction_pgStyleObject("pictureBox", "background-image", address);
tbfunction_pgTBObjSet("pictureBox", "visible", true);
]]>
</function>
</pictureBox>
Can you suggest a better alternative, please?
John