Blog Archive

RPGLE XML Parser - XML-SAX and XML-INTO sample code Part 6

Click here to read from first Chapter
Finally the Parsing program moving data out from Order.xml to OHEAD and ODETL db2 files.
h option(*nodebugio) dftactgrp(*no)   
fvxmlxrf   if   e           k disk                           
fohead     if a e           k disk                           
fodetl     if a e           k disk                           
                                                             
 /copy *libl/qrpglesrc,parser_h                              
                                                             
d $cmp            s              3s 0 inz(1)                 
                                                             
 * Main Routine                                              
 *                                                           
                                                             
 /free                                                       
       eval fileId   = 'MyOrders';                           
       eval fileName = 'Order.xml';                          
       clear oheadr;                                         
       clear odetlr;                                         
                                                             
       XML = '/MyXML/data' + '/' + %trim(fileName);          
       xml-sax %handler(mySaxHandler: ignoreMe)              
               %XML(XML: 'doc=file');                        
                                                             
       *inlr = *on;                                          
                                                             
 /end-free                                                   
                                               
 /copy *libl/qrpglesrc,parser                  
                                               
 * Data Manipulation                           
 *                                             
P myDataHandler   B                            
d myDataHandler   PI            10i 0          
d stackname                  65535a   varying  
d                                     value    
d stackval                   65535a   varying  
d                                     value    
                                               
 /free                                         
                                               
   eval fieldId = stackname;                   
   Chain (fileId:fieldId) Vxmlxrf;             
   If not %found(Vxmlxrf);                     
   return 0;                                   
   Endif;                                      
                                               
  //All you need is to Code this section       
  //Start section        

                     
   select;                                
                                          
   when x1unid = 'XML_13';                
                                          
       x1del  = 'A';                      
       x1cmp  = $cmp;                     
                                          
       write oheadr;                      
       clear oheadr;                      
                                          
   when x1unid = 'XML_12';                
                                          
       x2del  = 'A';                      
       x2cmp  = $cmp;                     
       x2ord  = x1ord;                    
                                          
       write odetlr;                      
       clear odetlr;                      
                                          
   when x1unid = 'XML_2';                 
         x1ord  = %dec(stackval: 9: 0);   
                                          
   when x1unid = 'XML_1';                                                               
         x1type = stackval;                                    
                                                               
   when x1unid = 'XML_3';                                      
         x1cust = stackval;                                    
                                                               
   when x1unid = 'XML_4';                                      
         eval      stackval = %Replace(                        
                      '.'                                      
                      : stackval                               
                      : %scan('-' : stackval)                  
                      : 1);                                    
         eval      stackval = %Replace(                        
                      '.'                                      
                      : stackval                               
                      : %scan('-' : stackval)                  
                      : 1);                                    
         x1ordt  = %dec(%char(%date(stackval:*eur):*iso0):8:0);
                                                               
   when x1unid = 'XML_5';                                      
         x1po   = stackval;                                    
                                                               
   when x1unid = 'XML_6';                                      
         x1otot = %dec(stackval:11: 2);                        
                                        
   when x1unid = 'XML_7';               
         x2seq  = %dec(stackval: 4: 0); 
                                        
   when x1unid = 'XML_8';               
         x2item = stackval;             
                                        
   when x1unid = 'XML_9';               
         x2desc = stackval;             
                                        
   when x1unid = 'XML_10';              
         x2qty  = %dec(stackval: 8: 0); 
                                        
   when x1unid = 'XML_11';              
         x2pric = %dec(stackval:11: 2); 
                                        
   endsl;                               
                                        
  //End section                         
                                        
   return 0;                            
 /end-free                              
P                 E     

Displaying output data from OHEAD and ODETL file in csv format for ease of display. Command used to make the csv file CPYTOIMPF.

Output data in Order Header File
"A",1,101,"O",20110501,"ABC","TEST PO - 123",99.99     
"A",1,102,"O",20110503,"ABC","TEST PO - 126",1212.12

Output data in Order Detail File
"A",1,101,1,"MCP-X2","Cuisinart MultiClad Pro",5,10.00              
"A",1,101,2,"DC25-X","Dyson Vacuum Cleaner",1,49.99                 
"A",1,102,1,"MMM-X123","Houdini Hand Blown Crystal",20,20.00        
"A",1,102,2,"LG123456","French Door Refrigerator",1,800.12

Click here for next Chapter

Recommended Reading