Topic
  • 3 replies
  • Latest Post - ‏2011-10-13T07:49:39Z by bogeybetsy
bogeybetsy
bogeybetsy
43 Posts

Pinned topic %SCANRPL

‏2011-10-12T06:39:18Z |
Hi,

I am converting special character data to XML predefined entity references. That is, the characters '<'>', '&', '"', and '''' to '&lt', '&gt', '&amp', '&quot', and '&apos' respectively.

I do it this way:
a@FldData = %ScanRpl( '<'&lt' : a@FldData );
a@FldData = %ScanRpl( '>' : '&gt' : a@FldData );
a@FldData = %ScanRpl( '&' : '&amp' : a@FldData );
a@FldData = %ScanRpl( '''' : '&apos' : a@FldData );
a@FldData = %ScanRpl( '"' : '&quot' : a@FldData );

Is there a better way?
Updated on 2011-10-13T07:49:39Z at 2011-10-13T07:49:39Z by bogeybetsy
  • barbara_morris
    barbara_morris
    442 Posts

    Re: %SCANRPL

    ‏2011-10-12T12:56:55Z  
    The & has to be handled first. If you handle it later, you'd change the &lt to &amplt which is not what you want. (Make sure your testing includes scenarios where you have both & and all of the other special characters.)

    But aside from that, I don't think there's a way to avoid doing 5 separate %scanrpl operations.
  • bogeybetsy
    bogeybetsy
    43 Posts

    Re: %SCANRPL

    ‏2011-10-13T07:48:25Z  
    The & has to be handled first. If you handle it later, you'd change the &lt to &amplt which is not what you want. (Make sure your testing includes scenarios where you have both & and all of the other special characters.)

    But aside from that, I don't think there's a way to avoid doing 5 separate %scanrpl operations.
    Yes, the entity reference for & should come first and the entity references end with a ';' as in '&'.

    I wish %SCANRPL could handle multiple "scan and replace strings" so I can do with one code statement instead of 5. Anyway, thanks Barbara. :-)
  • bogeybetsy
    bogeybetsy
    43 Posts

    Re: %SCANRPL

    ‏2011-10-13T07:49:39Z  
    The & has to be handled first. If you handle it later, you'd change the &lt to &amplt which is not what you want. (Make sure your testing includes scenarios where you have both & and all of the other special characters.)

    But aside from that, I don't think there's a way to avoid doing 5 separate %scanrpl operations.
    Yes, the entity reference for & should come first and the entity references end with a ; as in "&".

    I wish %SCANRPL could handle multiple "scan and replace strings" so I can do with one code statement instead of 5. Anyway, thanks Barbara. :-)