Enhancing XML output
It might happen that the information that you want to
express in XML format already exists in a group item in the DATA
DIVISION
, but you are unable to use that item directly to
generate an XML document because of one or more factors.
About this task
For example:
- In addition to the required data, the item has subordinate data items that contain values that are irrelevant to the XML output document.
- The names of the required data items are unsuitable for external presentation, and are possibly meaningful only to programmers.
- The required data items are broken up into too many components, and should be output as the content of the containing group.
There are various ways that you can deal with such situations. One possible technique is to define a new data item that has the appropriate characteristics, and move the required data to the appropriate fields of this new data item. However, this approach is somewhat laborious and requires careful maintenance to keep the original and new data items synchronized.
A superior approach that addresses most such problems is to use the new optional
phrases of the
XML GENERATE
statement in order to:- Provide more meaningful and appropriate names for the selected elementary items and for the group items that contain them.
- Exclude irrelevant data items from the generated XML by suppressing them based on their values.
The example that is referenced below shows a way to do so.