Example 11 Import file with missing intermediate parent names

This COBOL program illustrates how an XML document with some missing intermediate parent names may be converted into COBOL data format and stored in a COBOL data item. (This capability of handling missing intermediate parent names has been included to make programs that deal with "flattened" data items, such as Web services, less complicated.) A COBOL program and an XML document file may contain the same elementary items, but may not have the identical structure. XML Extensions offers a way to handle such cases where there is not a one-to-one match between the COBOL data item and the XML document structure. Consider the following situation, in which the COBOL program imports a predefined XML document that has some missing intermediate parent names.

A missing intermediate parent name is an XML element name that corresponds to an intermediate-level COBOL group name. For example, in the following COBOL data item, the XML element name, address-3, is an intermediate parent name.
 02 ADDRESS-1 PIC X(64) VALUE "101 Main St.".
 02 ADDRESS-2 PIC X(64) VALUE "Apt 2B".
 02 ADDRESS-3.
 03 CITY PIC X(32) VALUE "Smallville".
The structure of the corresponding XML document would be:
<my-address> <address-1>101 Main St.</address-1>
             <address-2>Apt 2B</address-2>
                         <state>KS</state> </address-3> 

In cases where the intermediate parent name is not needed to resolve ambiguity, XML Extensions will attempt to reconstruct the document structure on input. For example, if the input XML document contained the following information, then the intermediate parent names of address-3 and my-address would be added to produce an XML document compatible with the above document.

<root> <address-1>101 Main St.</address-1> <address-2>Apt 2B</address-2>
       <city>Smallville</city> <state>KS</state>

Example 11 illustrates this situation more fully.

This example uses the following XML statements: