Page 1 of 1

XML to PS file

PostPosted: Wed Nov 06, 2013 7:16 pm
by bobbysidhartha
Hi all,

I have a requirement.
I receive a file (text file) in xml format (file will be uploaded into the mainframe and becomes a PS (flat file) with XML data in it).

I need to parse the XML data in between the tags in the file and write those into a flat file..
Writing into a file (in a report format or a layout) is not the priroty..
I need to learn how to read the values from the XML file..

I hope the information is sufficient..

Please respond with your valuable comments and inputs..

Thank you

Re: XML to PS file

PostPosted: Wed Nov 06, 2013 7:36 pm
by NicC
There is no Rexx XML facility so you will just have to know your data and parse it or uae a language that has an XML facility e.g. COBOL.

Re: XML to PS file

PostPosted: Wed Nov 06, 2013 8:08 pm
by Ed Goodman
We had a VERY simple repeating XML and I parsed it like this:

Parse_Reply:                                             
  parse var sReply . '<c:referenceData>',               
                      sReply_Element,                   
                     '</c:referenceData>',               
                      sShrinking_Reply                   
  do while length(sReply_Element) > 0                   
    call Parse_Elements                                 
    parse var sShrinking_Reply . '<c:referenceData>',   
                                  sReply_Element,       
                                  '</c:referenceData>', 
                                   sShrinking_Reply     
  end                                                   
                                                         
return                                                   

Parse_Elements:                                     
  parse var sReply_Element,                         
  '<c:id>' sID '</c:id>' ,                           
  '<c:shortDesc>'sShort_Desc '</c:shortDesc>',       
  '<c:longDesc>' sLong_Desc '</c:longDesc>',         
  '<c:sortOrder>' sSort_Order '</c:sortOrder>'       
  say 'ID        :' sID                             
  say 'Short Desc:' sShort_Desc                     
  say 'Long Desc :' sLong_Desc                       
  say 'Sort Order:' sSort_Order                     
  line_out = ''                                     
  line_out = overlay(sID,line_out,1)                 
  line_out = overlay(sShort_Desc,line_out,3)         
  line_out = overlay(sLong_Desc,line_out,58)         
  line_out = overlay(sSort_Order,line_out,117)       
  push line_out                                     
 "EXECIO 1 DISKW OUTDATA"                           
return                                               



What's happening is that REXX finds the adta between the main tags <c:referenceData> and </c:referenceData>, puts that into sReply_Element and leaves the rest in sShrinking_Reply.

Then it calls Parse_Elements where the sub tags are parsed into variables.

Our XML looks like:
<root tag>
    <c:referenceData>
        <c:id>data</c:id>
        <c:shortDesc>data</c:shortDesc>
        <c:longDesc>data</c:longDesc>
        <c:sortOrder>data</c:sortOrder>
    </c:referenceData>
    <c:referenceData>
        <c:id>data</c:id>
        <c:shortDesc>data</c:shortDesc>
        <c:longDesc>data</c:longDesc>
        <c:sortOrder>data</c:sortOrder>
    </c:referenceData>
    <c:referenceData>
        <c:id>data</c:id>
        <c:shortDesc>data</c:shortDesc>
        <c:longDesc>data</c:longDesc>
        <c:sortOrder>data</c:sortOrder>
    </c:referenceData>
<root tag>

Re: XML to PS file

PostPosted: Wed Nov 06, 2013 8:13 pm
by Pedro
Use PARSE repeatedly:
/* first combine all of the records into one variable */

therest = myxml
Do while ( length(therest) > 0 )
  Parse var therest  part1 '<' tag1 '>' therest
  say part1
  If (tag1 ^= '') Then
    say '<'tag1'>'
End

Re: XML to PS file

PostPosted: Thu Nov 07, 2013 2:18 pm
by bobbysidhartha
Hi all,
Will try the cases and post the outcome..
Thank you for the valuable inputs...

Re: XML to PS file

PostPosted: Wed Nov 13, 2013 12:32 am
by Steve Coalbran
Hej! Where's that post?!
Try /*REXX*/                                             
ADDRESS ISPEXEC "CONTROL ERRORS RETURN "             
inds = "USER.EXEC(TRYXMLT)"                         
"ALLOC DD(SYSUT1)   DS("inds") SHR REUSE "           
"ALLOC DD(SYSUT2)   UNIT(VIO) SP(3 3)TR "           
"EXECIO * DISKR SYSUT1 (STEM ROW. FINIS "           
DO R = 1 TO row.0                                   
   line = row.r                                     
   DO l=1 BY 1 WHILE ( LENGTH(line) > 0 )           
     PARSE VAR line d1 '<' tag1 '>' line             
     IF( l>1 )THEN "EXECIO 1 DISKW SYSUT2 (STEM D"   
     IF (tag1<>'') THEN SAY '<'tag1'>'               
   END                                               
END                                                 
ADDRESS ISPEXEC "LMINIT  DATAID(QV) DDNAME(SYSUT2) "
ADDRESS ISPEXEC "VIEW    DATAID(&QV) "               
ADDRESS ISPEXEC "LMFREE  DATAID(&QV) "               
"DELSTACK"                                           
EXIT