Using the <eXpat/> XML Parser on IBM i:

I'm working on putting together information on how to use the open source eXpat XML parser on the IBM i, I'm using this parser from the HTTPAPI project to parse XML responses.

Since I've done the work of making it compile and run on the IBM i, it seems only natural to provide it for other people to use in their projects.


For documenation on how to use Expat from your ILE C programs, please take a look at the Expat home page. In particular, there's a link to an introductory article by Clark Cooper that's a little dated, but very helpful in getting started.

For documentation on how to use Expat from your ILE RPG programs, please read the following articles that I've written for the System iNetwork:
Using Expat from an RPG Program, Part 1
Using Expat from an RPG Program, Part 2
Using Expat from an RPG Program, Part 3
Using Expat from an RPG Program, Part 4

The preceding articles are based on the older (UTF-8 build) of Expat for IBM i. The following article describes the newer (UTF-16 build):
New Version of Expat with UTF-16 Support


My IBM i port of Expat contains all of the source code, plus a pre-compiled service program called "EXPAT." This way, you can use Expat on your system, even if you do not have the ILE C compiler installed.

Starting with version 2.0.0, I have Expat compiled with the XML_UNICODE symbol defined. This tells Expat to output UTF-16 when calling your procedures. This is a good thing for RPG programmers because RPG supports UTF-16 natively. (You code it as UCS2, then tell it to use CCSID(1200) which is UTF-16.)

Download Version 2.1.0 (Requires V5R4): Version 2.1.0 (SAVF format)

Download Version 2.1.0 (Requires V5R1): Version 2.1.0 (Zipped Source code -- source only)


 
How to download & install SAVF version:

  1. Download the save file (from the link above) to your PC

  2. Use FTP to copy the save file to your IBM i. Use the following steps:
    • Open a Command Prompt (MS-DOS Prompt)
    • Type: ftp your-iseries-name-here
    • Type: (enter your userid & password)
    • Type: binary
    • Type: quote site namefmt 1
    • Type: put expat-2.1.0.savf /qsys.lib/qgpl.lib/libexpat.savf
    • Type: quit

  3. You should now have a save file on your system called QGPL/LIBEXPAT. If you want to make sure it's there, you can type: DSPSAVF QGPL/LIBEXPAT

  4. If you already have a LIBEXPAT library, you might want to delete it to get rid of any previous versions. I cannot be held responsible if you lose anything important. Please make sure that nothing important is in this library before deleting anything. DLTLIB LIB(LIBEXPAT)

  5. Restore the library from the save file:
    RSTLIB SAVLIB(LIBEXPAT) dev(*SAVF) SAVF(QGPL/LIBEXPAT)

  6. If all is well, you can delete the save file: DLTF QGPL/LIBEXPAT

  7. If you want to use this with HTTPAPI, please follow these steps:
    • First, download HTTPAPI's LIBHTTP library. Instructions are on the HTTPAPI Web Page
    • CRTDUPOBJ OBJ(EXPAT) FROMLIB(LIBEXPAT) OBJTYPE(*SRVPGM) TOLIB(LIBHTTP)
    • CHGCURLIB CURLIB(LIBHTTP)
    • CRTCLPGM INSTALL SRCFILE(LIBHTTP/QCLSRC)
    • CALL INSTALL
    • When it asks if you'd like to build Expat from source code, choose 'N' because it's already been compiled.
    • When it asks if you're like to compile support for Expat into HTTPAPI, choose 'Y'

 
How to download & install ZIP version:

  1. Download the ZIP file (from the link above) to your PC

  2. Unzip the zip file to a windows directory such as c:\expat

  3. The ZIP file contains a .BAT file that will automatically use FTP to upload the proper files to IBM i.

  4. Open an MS-DOS prompt.

  5. Switch to the directory containing your unzipped download:
    cd c:\expat

  6. Run the batch file:
    UPLOAD.BAT your-ibmi.example.com LIBEXPAT your-userid your-password<

    For example my userid is SCOTTK and password is BIGBOY, so:
    UPLOAD.BAT i.scottklement.com LIBEXPAT scottk bigboy

  7. Now you should have a library named LIBEXPAT containing the source code. Log on to your IBM i with a standard 5250 client.

  8. Add the expat library to your library list
    ADDLIBLE LIBEXPAT *FIRST

  9. Create the program to compile expat:
    CRTCLPGM LIBEXPAT/MKEXPATCL SRCFILE(LIBEXPAT/QCLSRC)

  10. Run the program, passing the source library, object library, and target release:
    CALL MKEXPATCL PARM(LIBEXPAT LIBEXPAT V6R1M0)