XML for RPG and Procedural Languages Documentation

Readme
Installation
API Docs
Samples
Programming
License

How to build and run the XML, RPG and DB2 sample

What the sample program does
This sample program parses the XML file AddressBook.xml and inserts the data into a table in DB2. It provides an example of how to use the XML parser to read in data marked up in XML and put it into a database based on mapping information provided in a mapping construct called the MAPADDRESS table. Note that there are many ways you could provide the mapping constructs. In this case the MAPADDRESS table has a very simply reference to the XML markup information in one column and the corresponding DB2 column position in the other.

The SQL source for creating the two tables needed to run the program is included in the XML4PR400 QCLSRC source file, member ADRESSBK. The first table, adressbk, stores the data that is inserted into the database. The second table, mapaddress, stores information about what table elements in adressbk the XML tags and attributes correspond to.

Note: This program uses QxmlDOMString_transcode. QxmlDOMString_transcode always returns strings in the IBM037 coded character set. If this does not apply to your application you should use QxmlTranscode method to get string data back in the proper coded character set, providing DOMString as the input string and indicator.

Building the sample

Before you try to run this sample you should create the 2 DB2 tables and build the RPG sample programs that come with XML4PR400 qrpglesrc file.

  1. Create the two DB2 tables needed by the program:
    • RUNSQLSTM SRCFILE(XML4PR400/QCLSRC) SRCMBR(ADRESSBK) NAMING(*SQL)
  2. Create the two modules needed to run the program:
    • CRTSQLRPGI OBJ(<yourlibrary>/RPGDB2SAMP) SRCFILE(XML4PR400/QRPGLESRC) OBJTYPE(*MODULE)
    • CRTRPGMOD MODULE(<yourlibrary>/VECTORPROC) SRCFILE(XML4PR400/QRPGLESRC)
  3. Create the program by binding the two modules together with the XML4PR400 service program:
    • CRTPGM PGM(<yourlibrary>/RPGDB2SAMP) MODULE(<yourlibrary>/RPGDB2SAMP <yourlibrary>/VECTORPROC) BNDSRVPGM(XML4PR400/XML4PR400)

The XML file and DTD

The XML file and the DTD are provided as part of the samples data directory:
There are two files: AddressBook.xml and AddressBook.dtd

Running the program
Simply call the program:
call <yourlibrary>/rpgdb2samp

Viewing the results
If everything worked correctly there will be two entries added to the table Adressbk in the default library here called xml400addr. If you want to change the target library for the DB2 tables, you would need to change both the SQL script and the RPG program source. The data that is put into the table is pulled from the XML file /xml4pr400/AddressBook.xml. To see if the data was put into the table run the following commands:

  1. Start the SQL interpreter:
    strsql
  2. Select all entries from the adressbk table in the database:
    select * from xml400addr/adressbk

You can view the data in the XML file by calling:
wrklnk '/xml4pr400/AddressBook.xml'

Note:

    This is an RPG port of a Java program that was written to insert data from an XML file into a DB2 database on the iSeries. To see more information about the Java program you can load this page: Getting XML & DB2 UDB for AS/400 Talking.

    To view a white paper for the RPG version check the iSeries PartnerWorld Site under XML.

XML4PR - XML4C Interface Wrapper for RPG, C and COBOL
Copyright 2000,2001,2002 International Business Machines. All Rights Reserved.