XML GENERATE Statement
The XML GENERATE statement converts the data items in identifier-2 into an XML document that is stored in identifier-1.
A converted data element stores the value of the data item, the name of the data element, and XML markup. The element names are derived from the data names in identifier-2.
General Format:
XML GENERATE identifier-1 FROM identifier-2 [COUNT [IN] identifier-3]
[[ON] EXCEPTION imperative-statement-1]
[NOT [ON] EXCEPTION imperative-statement-2]
[END-XML]
Syntax Rules:
identifier-1is the data item into which the XML document is generated.identifier-1must be declared as an elementary or group item of category alphanumeric.identifier-1must not overlapidentifier-2oridentifier-3.identifier-1must be large enough to hold the XML document. A commonly used guideline is to giveidentifier-1a size that is 5-10 times the size ofidentifier-2. Ifidentifier-1is too small, theXML GENERATEstatement will produce an error condition.identifier-2is the group or elementary item to be converted into an XML document. It must not overlapidentifier-1oridentifier-3.identifier-3is a numeric data item. It must not overlapidentifier-1oridentifier-2.
General Rules:
identifier-1must not be described with theJUSTIFIEDclause, and cannot be a function identifier.- If
identifier-1is larger than the XML document, the trailing bytes will not be altered by the XML Generate operation. Data that was present from a previousGENERATEstatement could still be present, and not overwritten. For this reason, it is good practice toINITIALIZE identifier-1before performing theXML GENERATEstatement. Alternatively, you could useidentifier-3as a reference modifier when referring to the data inidentifier-1. identifier-2cannot be reference modified, and cannot be described with theRENAMESclause.XML GENERATEwill ignore the following inidentifier-2:- Unnamed elementary data items, or
FILLERdata items. - Slack bytes inserted for
SYNCRONIZEDitems. - Any items described with or subordinate to a
REDEFINESclause. - Any items decribed with the
RENAMESclause, - Any group item whose subordinate data items are all ignored.
- Unnamed elementary data items, or
- There must be at least one unignored elementary data item in the
identifier-2group item. - Excluding ignored data items, elementary data items in the
identifier-2group item must beCLASS ALPHABETIC,ALPHANUMERIC,NUMERIC, or be anINDEXitem. - The
COUNT INphrase manages the count of generated XML characters (in bytes) that are stored inidentifier-3. identifier-3must be an integer data item without the symbol "P" in its picture string.
ON EXCEPTION phrase
An EXCEPTION condition exists when an error occurs during the generation of the XML document. As an example, if identifier-1 is not large enough to hold the XML document, an EXCEPTION condition will be triggered. When an EXCEPTION condition is triggered, control passes to imperative-statement-1. The contents of identifier-1 are undefined. If a COUNT IN phrase was used, the number of characters generated can be retrieved in identifier-3.
NOT ON EXCEPTION phrase
If the ON EXCEPTION phrase is specified, and no EXCEPTION condition is triggered, then control passes to imperative-statement-2.
END-XML phrase
The END-XML phrase delimits the scope of both XML GENERATE and XML PARSE statements.
Nested XML statements
An XML GENERATE or XML PARSE statement located in an ON EXCEPTION imperative-statement is referred to as a nested (or conditional) XML statement. The scope of a conditional XML GENERATE or XML PARSE statement is terminated by either an END-XML phrase at the same level of nesting, or by a separator period.
Special Registers
See IBM Enterprise COBOL Programming Guide for more information.
XML-CODE
- The
XML-CODEspecial register indicates whether anXML GENERATEstatement executed successfully or an exception occurred during XML generation. A successful execution of theXML GENERATEstatement causes theXML-CODEspecial register to be set to 0. Exception conditions return non zero error codes to theXML-CODEspecial register. - The
XML CODEspecial register is implicitly defineds as:XML-CODE PICTURE S9(9) USAGE BINARY VALUE 0.
Details on handling non-zero error codes is detailed in the IBM Enterprise COBOL Programming Guide, in the "Handling XML Parse exceptions" chapter.
Converting data values, and element names
COBOL-IT uses IBM rules for converting elementary data items to character format, for data trimming, and for deriving element names.
Converting elementary data items
Converting elementary data items is the process of translating different data types into a character format. Alphanumeric data values are unchanged. Rules for converting elementary data items are detailed in the IBM Enterprise COBOL Programming Guide.
Data trimming
Data trimming is the application of rules that determine how leading and trailing zeroes, and spaces are handled for a variety of different cases. Rules for applying data trimming are detailed in the IBM Enterprise COBOL Programming Guide.
Element naming
Element naming is the process of translating element data names in identifier-2 into element tag names in the XML document. In most cases, you will see that your element tag name corresponds exactly to yur element name. However, there are cases where data names may contain characters that are illegal in XML. Rules for element naming are detailed in the IBM Enterprise COBOL Programming Guide.