RPGLE XML Parser – XML-SAX as well as XML-INTO sample code Part 3

Click hither to read from commencement Chapter
Lets create down amongst a sample XML information of Orders coming to your organization from Third political party software.

<?xml version="1.0" encoding="UTF-8"?> <Orders> <Order Type="Sales"> <OrderID>101</OrderID> <CustNumber>ABC</CustNumber> <OrderDate>01-05-2011</OrderDate> <CustPONumber>TEST PO - 123</CustPONumber> <OrderTotal>99.99</OrderTotal> <OrderLine> <OrderlineID>1</OrderlineID> <ItemID>MCP-X2</ItemID> <ItemDescription>Cuisinart MultiClad Pro</ItemDescription> <Quantity>5</Quantity> <Price>10.00</Price> </OrderLine> <OrderLine> <OrderlineID>2</OrderlineID> <ItemID>DC25-X</ItemID> <ItemDescription>Dyson Vacuum Cleaner</ItemDescription> <Quantity>1</Quantity> <Price>49.99</Price> </OrderLine> </Order> <Order Type="Sales"> <OrderID>102</OrderID> <CustNumber>ABC</CustNumber> <OrderDate>03-05-2011</OrderDate> <CustPONumber>TEST PO - 126</CustPONumber> <OrderTotal>1212.12</OrderTotal> <OrderLine> <OrderlineID>1</OrderlineID> <ItemID>MMM-X123</ItemID> <ItemDescription>Houdini Hand Blown Crystal</ItemDescription> <Quantity>20</Quantity> <Price>20.00</Price> </OrderLine> <OrderLine> <OrderlineID>2</OrderlineID> <ItemID>LG123456</ItemID> <ItemDescription>French Door Refrigerator</ItemDescription> <Quantity>1</Quantity> <Price>800.12</Price> </OrderLine> </Order> </Orders> 

Now to pose this XML into a DB2 database nosotros require to create the Order Header together with Detail Files that volition conk populated when nosotros parse this XML input data.

Member      Type        Text                
ODETL       PF          Order Detail file    

OHEAD       PF          Order Header file    

DDS Source for Order Detail Physical File

A                                      UNIQUE                     H5N1          R ODETLR                                               H5N1            X2DEL          1A         COLHDG('Status')            *                                     H5N1 = Active                  *                                     B = XML Processed          H5N1            X2CMP          3S 0       COLHDG('Company No.')      H5N1            X2ORD          9S 0       COLHDG('Order Number')     H5N1            X2SEQ          4S 0       COLHDG('Order Line No.')   H5N1            X2ITEM        20A         COLHDG('Item Number')      H5N1            X2DESC        30A         COLHDG('Item Description')  H5N1            X2QTY          8S 0       COLHDG('Order Quantity')   H5N1            X2PRIC        11S ii       COLHDG('Item Price')       H5N1          K X2CMP                                                H5N1          K X2ORD                                                H5N1          K X2SEQ   

DDS Source for Order Header Physical File

A                                      UNIQUE                        H5N1          R OHEADR                                                  H5N1            X1DEL          1A         COLHDG('Status')               *                                     H5N1 = Active                     *                                     B = XML Processed             H5N1            X1CMP          3S 0       COLHDG('Company No.')         H5N1            X1ORD          9S 0       COLHDG('Order Number')        H5N1            X1TYPE         1A         COLHDG('Transaction Type')     *                                     O = Sales Order                *                                     C = Credit                    H5N1            X1ORDT         8S 0       COLHDG('Order Date')          H5N1            X1CUST        10A         COLHDG('Customer Number')     H5N1            X1PO          20A         COLHDG('PO Number')           H5N1            X1OTOT        11S ii       COLHDG('Order Total')         H5N1          K X1CMP                                                   H5N1          K X1ORD  

Now that nosotros accept our input (XML) together with output physical files, nosotros are create to parse. We tin right away write the parser programme only I accept added a measurement hither to repose the Coding. Lets country you lot desire to map the ItemID to a champaign inwards the RPGLE program, therefore you lot accept to reference the whole path /Orders/Order/OrderLine/ItemID  inwards the programme to conk the value. So what I create is create a Cross-Ref mapping file for purpose inwards the parser program.

DDS rootage for XML Cross-Reference File (VXMLXRF)

A                                      UNIQUE                    H5N1                                      REF(VAIREF)               H5N1          R XMLXRFR                                             H5N1            X1DEL     R               REFFLD(##DEL)             H5N1            X1FILEID      20A         COLHDG('XML File ID')     H5N1            X1UNID        20A         COLHDG('Short Name')      H5N1            X1FLDID     2000A         COLHDG('XML Field ID')    H5N1                                      VARLEN                    H5N1                                                                H5N1          K X1FILEID                                            H5N1          K X1FLDID  

DDS rootage for XML Cross-Reference Logical File (VXMLXRF1)

A          R XMLXRFR                   PFILE(VXMLXRF)        H5N1                                                            H5N1          K X1FILEID                                        H5N1          K X1UNID     

Click hither for side past times side Chapter

Recommended Reading

Hosting Unlimited Indonesia


Sumber http://www.mysamplecode.com/