RPGLE XML Parser – XML-SAX together with XML-INTO sample code Part 5

Click hither to read from showtime Chapter

Generate Parser Cross-Ref File for role inwards Parsing the XML data

h option(*nodebugio) dftactgrp(*no)       fvxmlxrf   if a e           k disk                                    fvxmlxrf1  if   e           k disk    rename(xmlxrfr:record1)         f                                     prefix(#)                                                                                              /copy *libl/qrpglesrc,parser_h                                                                                                             d $counter        sec              5s 0 inz(0)                                                                                                 * Main Routine                                                        *                                                                                                                                          c     *entry        plist                                             c                   parm                    fileId             c                   parm                    filePath                                                                           /free                                                                                                                               XML = %trim(filePath);                                         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 non %found(Vxmlxrf);                                                                                                       clear xmlxrfr;                                                 eval x1fileid = fileId;                                        eval x1fldid  = fieldId;                                                                                                      dou non %found(Vxmlxrf1);                                      eval $counter = $counter + 1;                                  eval x1unid   = 'XML_' + %trim(%editc($counter:'Z'));          Chain (fileId:x1unid) Vxmlxrf1;                                enddo;                                                                                                                        write xmlxrfr;                                                                                                                EndIF;                                                                                                                    provide 0;                                                    /end-free                                                     P                 eastward    

Command to Call the Parser Cross-Ref Program

              CMD        PROMPT('Generate Parser Cross Ref File')                                                                                                   PARM       KWD(FILEID) TYPE(*CHAR) LEN(20) MIN(1) +                                     MAX(1) PROMPT('File Id')                                      PARM       KWD(FILEPATH) TYPE(*CHAR) LEN(250) MIN(1) +                                  MAX(1) PROMPT('File Path')                       

Create the ascendence using CRTCMD

CRTCMD CMD(command_name) PGM(program_name)     

Now piece of occupation the ascendence over the XML file giving it an ID

command_name FILEID(file_id) FILEPATH(file_path)

I used the file id every bit MyOrders thence hither is my output inwards VXMLXRF file afterwards running that command.

XML File ID           Short Name            XML Field ID                                                                                                                MyOrders              XML_1                 /Orders/Order/@Type                     MyOrders              XML_2                 /Orders/Order/OrderID                   MyOrders              XML_3                 /Orders/Order/CustNumber                MyOrders              XML_4                 /Orders/Order/OrderDate                 MyOrders              XML_5                 /Orders/Order/CustPONumber              MyOrders              XML_6                 /Orders/Order/OrderTotal                MyOrders              XML_7                 /Orders/Order/OrderLine/OrderlineID     MyOrders              XML_8                 /Orders/Order/OrderLine/ItemID          MyOrders              XML_9                 /Orders/Order/OrderLine/ItemDescription MyOrders              XML_10                /Orders/Order/OrderLine/Quantity        MyOrders              XML_11                /Orders/Order/OrderLine/Price           MyOrders              XML_12                /Orders/Order/OrderLine                 MyOrders              XML_13                /Orders/Order                           MyOrders              XML_14                /Orders   

IMPORTANT :  Never clear the VXMLXRF file if y’all larn a novel layout for the same XML, simply piece of occupation the ascendence in ane lawsuit again over the novel XML file as well as it volition uncovering whatever novel fields as well as map them. Otherwise if y’all clear the file it may lift the sometime fields to novel id as well as and then y’all convey to become alter your Parsing plan to reference the novel Ids.

Click hither for adjacent Chapter

Recommended Reading

Hosting Unlimited Indonesia


Sumber http://www.mysamplecode.com/