This example illustrates how XML Extensions may work with sparse arrays. XML Extensions distinguishes between an empty occurrence and a non-empty occurrence. An occurrence is an empty occurrence when all of its numeric elementary data items have a zero value and all of its nonnumeric elementary data items contain spaces; otherwise, the occurrence is a non-empty occurrence. A sparse array is an array that contains a combination of empty and non-empty occurrences. Empty occurrences need not be exported unless they are needed to locate (determine the subscript) of a subsequent non-empty occurrence. Normally, this means that trailing empty occurrences, that is, a contiguous series of empty occurrences at the end of the array, are not exported. Sparse arrays may also be imported.
This program first writes (or exports) several XML document files from the content of a COBOL data item (using various combinations of the
XML ENABLE ATTRIBUTES,
XML DISABLE ATTRIBUTES,
XML ENABLE ALL-OCCURRENCES, and
XML DISABLE ALL-OCCURRENCES statements). Then the program reads (or imports) the same XML documents (plus a couple of pre-existing documents) and places the content in the same COBOL data item.
This example uses the following XML statements:
- XML INITIALIZE, which initializes or opens a session with XML Extensions.
- XML EXPORT FILE, which constructs an XML document (as a file) from the content of a COBOL data item.
- XML IMPORT FILE, which reads an XML document (from a file) into a COBOL data item.
- XML ENABLE ATTRIBUTES, which causes exported XML document to contain descriptive (COBOL-oriented) attributes.
Note: Although the default is not to add descriptive attributes to an XML document (see XML DISABLE ATTRIBUTES in the next item), among the attributes that may be added is the "subscript" attribute. This attribute contains the one-relative index of the occurrence within the array. When an XML document is imported, this subscript attribute is used (if present) to place the occurrence correctly within the array. If the subscript attribute is not present, then occurrences are assumed to occur sequentially.
- XML DISABLE ATTRIBUTES, which causes exported XML documents not to contain descriptive attributes.
Note: The default is not to add descriptive attributes to an XML document.
-
XML ENABLE ALL-OCCURRENCES, which causes all occurrences of a data item to be exported to an XML document.
- XML DISABLE ALL-OCCURRENCES, which causes only certain occurrences to be exported to the XML document.
Note: The default is to export only certain occurrences to the XML document.
-
XML TERMINATE, which terminates or closes the session with XML Extensions.