How to replace XML reserved special characters from a block of string?

pablo_barua
Kilo Explorer

I need some help. I am send a xml file with details field values which may have lot of special reserve characters. I am writing a script where I need to find and replace all the special characters that XML reserves. Ex:

Special Character     Escape Sequence Purpose

&                                                         &                     Ampersand sign

'                                                             '                   Single quote

"                                                           "                   Double quote

>                                                         >                       Greater than

<                                                         &lt;                       Less than

I am writing and onChange() client script to change the description field to replace all the special character with appropriate decoded string.

    var descr = g_form.getValue('description');

    strReplace = descr;

    strReplace = strReplace.replace(/&/g, '&amp;amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');

    g_form.setValue('u_hpsm_details',strReplace);

Can someone help me please? I am stuck... Thanks in advance.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

This is my string I am trying -

Every time we are trying to upload the BP we are getting the below "Error"

"Error message from SAP : Material AP-2X2-D607 is not defined , language EN"

Have 'attached' the screenshot for &reference.

"Please advise." - chikkamallaiah@gmail.com<mailto:nchikkamallaiah@gmail.com>

________________________________

reply from: nchikkamallaiah@gmail.com<mailto:nchikkamallaiah@gmail.com>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

This is the output I get with that code - For very odd reason only 3rd line gets converted only rest does not.

Every time we are trying to upload the BP we are getting the below "Error"

"Error message from SAP : Material AP-2X2-D607 is not defined , language EN"

Have &apos;attached&apos; the screenshot for &amp;reference.

"Please advise." - chikkamallaiah@gmail.com<mailto:nchikkamallaiah@gmail.com>

________________________________

reply from: nchikkamallaiah@gmail.com<mailto:nchikkamallaiah@gmail.com>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

1 REPLY 1

Jace Benson
Mega Sage

Did you get this resolved?  It appears your code is not showing all the syntax.  Maybe thats the problem, maybe it was an issue when posting.  In anycase I'm curious.