XML is fast becoming the preferred format for data interchange in todays e-business world. Leveraging this technology is something of keen interest to iSeries COBOL shops. Lets explore how COBOL applications can work with XML.
XML Considerations
A first step is to choose a location for the XML documents. On the iSeries server, the most likely source for XML documents is the IFS. Compared to the QSYS file system, the IFS space provides more flexible advantages in terms of file format and the CCSID encoding.
When parsing XML documents with COBOL, you have a couple of options. IBMs XML Toolkit for iSeries (5733-XT1), which contains the XML for procedural parser, is the obvious and simple choice. In essence, the parser provides a set of APIs for procedural languages such as COBOL and RPG to interact with the underlying XML parser.
Also, with the introduction of IBM i5/OS V5R3, an embedded XML parser is provided with ILE COBOL. This can be invoked using the newly introduced XML PARSE syntax.
At this point, iSeries users can only generate XML documents programmatically. Thus, when generating an XML document, the document content should be well determined at runtime. Users can simply generate the output document while adhering to the XML format.
Parsing XML Documents
Parsing XML documents plays a major role in enabling XML technology for COBOL applications. For further insight, lets more closely examine the two aforementioned parsing options.
Code Sample 1, Code Sample 2 and Code Sample 3 illustrate a simple "address book" COBOL application. The application is designed to read in an XML document containing several address entries from the IFS. The XML document is then parsed and address entries are mapped to the corresponding fields as defined in DB2 Universal Database (UDB) for iSeries. Code samples 1 and 2 are the main program and the event handler program, respectively, using the XML Toolkit for iSeries. Code Sample 3 uses the V5R3 XML PARSE statement.
Summary
The coding effort and simplicity of the XML PARSE statement are evident from the examples. However, XML PARSE currently supports only Simple API for XML (SAX) parsing. For COBOL programmers interested in and Document Object Model (DOM) parsing, the APIs provided by the XML Toolkit for iSeries offer a complementary alternative.
Browse products and services for Developer.