XML to PS file



IBM's Command List programming language & Restructured Extended Executor

XML to PS file

Postby bobbysidhartha » Wed Nov 06, 2013 7:16 pm

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
bobbysidhartha
 
Posts: 2
Joined: Sat Nov 12, 2011 6:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: XML to PS file

 

Re: XML to PS file

Postby NicC » Wed Nov 06, 2013 7:36 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: XML to PS file

Postby Ed Goodman » Wed Nov 06, 2013 8:08 pm

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>
Ed Goodman
 
Posts: 342
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: XML to PS file

Postby Pedro » Wed Nov 06, 2013 8:13 pm

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
Pedro Vera
User avatar
Pedro
 
Posts: 569
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 39 times

Re: XML to PS file

Postby bobbysidhartha » Thu Nov 07, 2013 2:18 pm

Hi all,
Will try the cases and post the outcome..
Thank you for the valuable inputs...
bobbysidhartha
 
Posts: 2
Joined: Sat Nov 12, 2011 6:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: XML to PS file

Postby Steve Coalbran » Wed Nov 13, 2013 12:32 am

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
Steve
User avatar
Steve Coalbran
 
Posts: 102
Joined: Wed Apr 06, 2011 11:49 am
Location: Stockholm, Sweden
Has thanked: 5 times
Been thanked: 1 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post