This article explains how to import business XML documents containing an unknown number of repeating items.
Problem:
Business oriented XML documents often contain an unknown number of repetitions of complex elements. For example, a web service based credit application processing system may return any number of credit acceptances, with each credit acceptance structure being complex. Another example would be a document representing a series of purchase orders, with each purchase order including any number of line items. If such a document is imported in its entirety, the COBOL data structure must use an OCCURS to describe the group data item that represents the top level repeating element. However, the OCCURS clause requires a fixed upper bound, and most XML documents of this type do not have a specified maximum number of repeating elements, thereby almost guaranteeing that some document will be presented that exceeds the maximum of the OCCURS clause.
Resolution:
Version 12 of XML Extensions introduces a new interface, XML SET XSL-PARAMETERS. This new interface allows the COBOL program to pass parameter values to the XSLT style sheet used in an XML import or export. One use of this new interface is to solve the unbounded repeated element problem. The basic mechanism is demonstrated in the attached example. The example does not manipulate complex repeated elements, so that the parameter mechanism is obvious.
The XML IMPORT FILE loop that uses the importsingle.xsl style sheet takes the most basic approach of importing a single repetition for each XML IMPORT FILE call. While this is very simple, it may prove too inefficient for larger documents, as the input document must be parsed for each XML IMPORT FILE call.
The importsome.xsl style sheet that is used in the last XML IMPORT FILE loop corrects some of the potential inefficiencies of the combination of countelements.xsl/importsingle.xsl by reducing the number of times the input document must be parsed. importsome.xsl accepts two parameters which indicate the repetitions that may be imported, computed from the starting repetition and the limit of the OCCURS clause. The importsome.xsl not only reports back how many repetitions were actually imported, but also reports how many repetitions remain in the input document after those that were imported. By the interaction of the COBOL program and the style sheet through the XSL-PARAMETERS values, the entire document is imported in fewer calls to XML IMPORT FILE, and the XML IMPORT FILE to retrieve the count of repetitions is eliminated.
By using the technique modeled in the importsome.xsl example, the programmer may allocate a number of occurrences that will allow importing of typical documents in one XML IMPORT FILE call, but will still be able to deal with documents that exceed the maximum of the OCCURS clause.