Home > AS/400 Tips > iSeries programmer tips > Transform XML into iSeries readable form, easily
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Transform XML into iSeries readable form, easily


Shalom Carmel
10.22.2002
Rating: -3.08- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Disoriented by SAX vs. DOM? Baffled by XML APIs? You are not alone. Writing RPGLE code to parse XML documents can be a tedious task. There is, however, a (free) utility called Xalan that will immensely ease your job, and let concentrate on the business rather than the bytes.

Xalan is a Java XSL parser, that will take as input 2 XML files: The first is the XML we want to transform, and the second is a XML file that defines the transformation. The transformation can output another XML, an HTML file, a PDF file (using special extensions).

Of special interest to iSeries professionals is the fact that a transformation can output a regular, flat text file, that is suited for import into a DB2 table.

You can find many examples of XSL transformations on the Web, but here is a real world example that is relevant in our context.

The Bank of Israel publishes a daily XML file with the currency rates.

With the attached code, you can find a sample of this file, and the XSL to transform it into a Comma Separated Values text file.

The result file can be imported into a DB2 table using CPYFRMIMPF command.

How to get Xalan to your iSeries computer?

-----------------------------------------------------------------

If you have VRR1, and have Java, then chances are that it is already installed.

Type WRKLNK OBJ('/QIBM/ProdData/OS400/xml/lib/*')

If you see the files xalan101.jar and xerces103.jar then you are already set up.

If you do not have the files, you can get them at here.

Note: This is an OLD version of Xalan. New version are available, but have not been tried by me, yet. If you decide to use a newer Xalan distribution, pay attention to the CLASSPATH variable.

Create a new IFS directory called XML:
MKDIR '/xml'

Transfer the ZIP file via FTP to the XML directory.

Run the following command (it's


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
iSeries CL programming
Checking in on your IBM i authorization lists
Running PHP open source applications: NOBODY needs authority
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
CL program for daily backups
An automated CL method of moving a query from AS/400 to Excel
Changing user password expiration
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Advanced Job Scheduler help
How do I retrieve the source for an output queue description to put in to a CL program?

iSeries programmer tips
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Running PHP open source applications: NOBODY needs authority
Programming for the Web on the IBM i, what is possible
Using geocoding on AS/400 to enhance your Web presence
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
Documenting nested program structures on the AS/400
What is an integrated database?
An automated CL method of moving a query from AS/400 to Excel

RPG iSeries programming
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400
How to: Sort arrays using RPGIV
How to: Create an RPGLE array
How to use an embedded SQL statement and display the result in a subfile
Eight steps for creating program documentation using AS/400 utilities

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


best to submit to batch):
QSH CMD('cd /xml; ajar -x -r xalan-j_1_0_1.zip')

About the attached code:

=================================================================
The CL program takes 5 parameters:
XML - The file to be translated.
XSL - The transformation description.
OUT - The result file.
CSSID - The code page of the result file.
VER - The AS/400 version. If *PRV, the script assumes that you installed Xalan manually according to the above listed instructions. Use *PRV in case you did not find the xalan101.jar file, even if you have 5.1 or higher.

XALAN *cmd:

=================================================================
/* CRTCMD CMD(XALAN) PGM(*LIBL/XALANCPP) ... */
CMD PROMPT('Translate XML using XSLT')
PARM KWD(XML) TYPE(*PNAME) LEN(256) MIN(1) +
CASE(*MIXED) PROMPT('Full XML file path')

PARM KWD(XSL) TYPE(*PNAME) LEN(256) MIN(1) +
CASE(*MIXED) PROMPT('Full XSL file path')

PARM KWD(out) TYPE(*PNAME) LEN(256) MIN(1) +
CASE(*MIXED) PROMPT('Full Result file path')

PARM KWD(CCSID) TYPE(*CHAR) LEN(7) PROMPT('CCSID +
of result file')

PARM KWD(VER) TYPE(*CHAR) LEN(7) RSTD(*YES) +
DFT(V5R1M0) VALUES(V5R1M0 V5R2M0 *PRV) +
PROMPT('OS400 release')
/* End of Command XALAN */

XALANCPP *PGM:

=============================================================
PGM PARM(&XML &XSL &OUT &CCSID &VER)
DCL VAR(&JAVA) TYPE(*CHAR) LEN(1024)

DCL VAR(&qshell) TYPE(*CHAR) LEN(1024)
DCL VAR(&XML) TYPE(*CHAR) LEN(256)
DCL VAR(&XSL) TYPE(*CHAR) LEN(256)
DCL VAR(&OUT) TYPE(*CHAR) LEN(256)
DCL VAR(&CCSID) TYPE(*CHAR) LEN(7)
DCL VAR(&VER) TYPE(*CHAR) LEN(6)

/* Prepare java call */
IF COND(&VER = '*PRV') THEN(DO)

CHGVAR VAR(&JAVA) VALUE('java -classpath +
/xml/xalan_1_0_1/xalan.jar:/xml/xalan_1_0_1+

/xerces.jar:. + org.apache.xalan.xslt.Process ' *BCAT +
'-IN ' *BCAT &XML *BCAT ' -XSL ' *BCAT +
&XSL *BCAT ' -OUT ' *BCAT &OUT *BCAT ' +
-TEXT')

enddo
ELSE CMD(DO)
CHGVAR VAR(&JAVA) VALUE('java -classpath +
/QIBM/ProdData/OS400/xml/lib/xalan101.jar:/+
QIBM/ProdData/OS400/xml/lib/xerces103.jar:. +
org.apache.xalan.xslt.Process ' *BCAT +
'-IN ' *BCAT &xml *BCAT ' -XSL ' *BCAT +
&xsl *BCAT ' -OUT ' *BCAT &out *BCAT ' -TEXT'
enddo

STRQSH CMD(&JAVA)
/* Change CCSID of OUT file
CHGVAR VAR(&QSHELL) VALUE('setccsid' *bcat &ccsid *BCAT &out)
STRQSH CMD(&qshell)

RETURN
EXIT: ENDPGM

/* End of Program XALANCPP */

Sample XML to translate:

Note: The encoding in the original XML file is wrong.

==============================================================

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts