Page 1 of 1

How to replace '&' with '&' and more

PostPosted: Sat Oct 06, 2007 5:02 am
by 96B5A4485
Hi,

I have tried a lot and am not able to achieve this.
Using DFSORT SORT step, I have created an xml output file. But if my output file had any of these characters '&', '<', '>', ''' (single quotes) or '"' (double quotes) then the xml fails to open.

Option 1:
If my data is wrapped between '<![CDATA[' and ']]>' tags, then I won't have a problem. But when I did this, the '[' and ']' characters came out as junk characters and xml failed again.

 
   SORT FIELDS=COPY                 
   OUTFIL FNAMES=MYEXT,REMOVECC,   
       BUILD=(4:C'<Row>',/,             
          5:C'<Cell><Data><![CDATA[',     
          1,20,JFY=(LENGTH=20,SHIFT=LEFT),
          C']]></Data></Cell>',/,         
          4:C'</Row>')                     


This is what I get:
<!CDATAsome data   Ã™Ã™>


Option 2:
Instead of using CDATA tags, there will not be any problem, if I replaced:
'&' with '&amp;'
'<' with '&lt;'
'>' with '&gt;'
''' with '&apos;'
'"' with '&quot;'
I tried using CHANGE= option, but if I do not know the position of these characters in my file (say, these characters can be anywhere from 1 to 20th position in my input file), then how do I achieve this?

Can any of you help me with any of my options (or is there any new option for me)?

Much appreciated.

Re: How to replace '&' with '&amp;' and more

PostPosted: Sat Oct 06, 2007 5:43 am
by Frank Yaeger
I believe DFSORT is outputting the characters you used as input, but your display of the output can't handle them.

On the input side [ is X'BA'. When I run your job, I get the line with [ as:

    <Cell><Data><! CDATA AAA...


and it looks like the [ is missing. But when I display this line in hex with DFSORT, it's:

404040404CC38593936E4CC481A3816E4C5ABAC3C4C1E3C1BAC1C1C1...
                                    **


You can see that the X'BA' is actually there (I put ** below it to identify it).

So I'd say that DFSORT is most likely outputting the characters you told it to and the problem lies somewhere else.

Re: How to replace '&' with '&amp;' and more

PostPosted: Wed Oct 10, 2007 2:32 am
by 96B5A4485
Hi Frank,

You are right. The hex characters X'BA' is in the output, but still, when I FTP the file and open with notepad/excel/IE, it shows something else. So, I tried the other way. I transferred the file with chars '[' and ']' to mainframe and was surprised to see that the char '[' was translated to X'AD' and ']' to X'BD'. Now, I reran my DFSORT with these hex chars and it worked.

Just curious about my option 2. Do you know how to replace the ";" with "&amp;" and so on (as mentioned in the original post) using DFSORT?

Thanks.

Re: How to replace '&' with '&amp;' and more

PostPosted: Wed Oct 10, 2007 3:20 am
by Frank Yaeger
Just curious about my option 2. Do you know how to replace the ";" with "&amp;" and so on (as mentioned in the original post) using DFSORT?


If you're asking about finding a character (e.g. '>') anywhere in a record and replacing it with a string (e.g. '&gt;'), DFSORT does not have any built-in functions for that.

Re: How to replace '&' with '&amp;' and more

PostPosted: Wed Oct 10, 2007 9:40 pm
by 96B5A4485
Thanks Frank.

Re: How to replace '&' with '&amp;' and more

PostPosted: Tue Jul 29, 2008 5:00 am
by Frank Yaeger
If you're asking about finding a character (e.g. '>') anywhere in a record and replacing it with a string (e.g. '&gt;'), DFSORT does not have any built-in functions for that.


DFSORT now has a find and replace capability with z/OS DFSORT V1R5 PTF UK90013. For example:

   OPTION COPY
   INREC FINDREP=(INOUT=(C'&',C'&amp;',C'<',C'&lt;',C'>',C'&gt;',
      C'''',C'&apos;',C'"',C'&quot;'))


For complete details on the new FINDREP function and the other new functions available with PTF UK90013, see:

http://www.ibm.com/systems/support/stor ... /mvs/ugpf/