Working with XML Data

Applications written in ACUCOBOL-GT can interact with many different forms of data, including data marked with eXtensible Markup Language (XML).

ACUCOBOL-GT provides a variety of ways to interact with XML data. Characteristics of the XML data in a particular usage might be a major factor in determining which technique is best suited to your needs.

While XML concepts are described in more detail below, most XML data can be most simply characterized into document-oriented and record-oriented applications. Document-oriented XML data might exhibit deep nesting of data structures, mixed content, external entities and the like. Record-oriented XML data is much more flat and typically have many repetitions of the same flat structure; this structure is often seen in use with data transmitted to or from relational databases.

The XML data mechanisms provided by ACUCOBOL-GT are summarized in this section.

AcuXML

AcuXML is a runtime-resident file system interface. AcuXML reads XML data and transparently converts it to sequential files for COBOL processing, and similarly converts COBOL output data into XML format when required. Using Extended File Descriptors (XFDs) created at compile time, AcuXML maps the data transparently, making it easy to read and write record-oriented XML data.

To facilitate the use of AcuXML, ACUCOBOL-GT includes a developer utility called xml2fd that creates File Descriptors (FDs) and SELECT statements from existing XML files. Although you may need to tune the results, you can include the FDs and SELECTS in your ACUCOBOL-GT program to prepare it for use with XML data.

XML Extensions Library

The XML Extensions Library is provided as a DLL/shared object library. XML Extensions allows data to be imported from an XML document by converting data elements (as necessary) and storing the results directly into a matching COBOL data structure in the DATA DIVISION. Similarly, data is exported directly from a COBOL data structure by converting the COBOL data elements (as necessary) and storing the results in an XML document. XML Extensions is particularly suited to document-oriented XML data.

XML GENERATE and PARSE

ACUCOBOL-GT supports the IBM Enterprise COBOL XML GENERATE and XML PARSE statements. XML PARSE gives you a way to parse XML and process it in a COBOL program, associating processing procedures with the exception and non-exception cases that can result from the parse. XML GENERATE gives you a way to translate COBOL data into XML.

C$XML

For those who want more control over the parsing of data, ACUCOBOL-GT provides the C$XML library routine. This routine lets you define precisely which elements or attributes of the data to parse. For instance, you can request the handle of the entire XML tree, the first child element of the handle passed, the next sibling element, the number of attributes in an element, the name and value of the attributes, and so on. C$XML gives you much lower-level control over the parsing of XML data compared to AcuXML, but it requires more programming effort and XML knowledge.