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-1
is the data item into which the XML document is generated.identifier-1
must be declared as an elementary or group item of category alphanumeric.identifier-1
must not overlapidentifier-2
oridentifier-3
.identifier-1
must be large enough to hold the XML document. A commonly used guideline is to giveidentifier-1
a size that is 5-10 times the size ofidentifier-2
. Ifidentifier-1
is too small, theXML GENERATE
statement will produce an error condition.identifier-2
is the group or elementary item to be converted into an XML document. It must not overlapidentifier-1
oridentifier-3
.identifier-3
is a numeric data item. It must not overlapidentifier-1
oridentifier-2
.
General Rules:
identifier-1
must not be described with theJUSTIFIED
clause, and cannot be a function identifier.- If
identifier-1
is larger than the XML document, the trailing bytes will not be altered by the XML Generate operation. Data that was present from a previousGENERATE
statement could still be present, and not overwritten. For this reason, it is good practice toINITIALIZE identifier-1
before performing theXML GENERATE
statement. Alternatively, you could useidentifier-3
as a reference modifier when referring to the data inidentifier-1
. identifier-2
cannot be reference modified, and cannot be described with theRENAMES
clause.XML GENERATE
will ignore the following inidentifier-2
:- Unnamed elementary data items, or
FILLER
data items. - Slack bytes inserted for
SYNCRONIZED
items. - Any items described with or subordinate to a
REDEFINES
clause. - Any items decribed with the
RENAMES
clause, - 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-2
group item. - Excluding ignored data items, elementary data items in the
identifier-2
group item must beCLASS ALPHABETIC
,ALPHANUMERIC
,NUMERIC
, or be anINDEX
item. - The
COUNT IN
phrase manages the count of generated XML characters (in bytes) that are stored inidentifier-3
. identifier-3
must 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-CODE
special register indicates whether anXML GENERATE
statement executed successfully or an exception occurred during XML generation. A successful execution of theXML GENERATE
statement causes theXML-CODE
special register to be set to 0. Exception conditions return non zero error codes to theXML-CODE
special register. - The
XML CODE
special 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.