The XML PARSE is an event-driven process:
reads through the XML
at all elements, attributes, texts generates an event
events are processed in a handler procedure
The PROCESSING PROCEDURE defines the handler where the events are processed.
The VALIDATING forces the parser to go through the XML source; if error are found, enters into the ON EXCEPTION branch; if not found, does nothing. It has 2 formats:
VALIDATING (checks for existence of < > marks, closing tags, forbidden characters, quote marks)
VALIDATING <xml schema text variable> (checks against structure, type, order, constraints defined in the XSD data)
The flow enters into the ON EXCEPTION branch in case any parsing error is raised.
Typical errors in XML, detected based on the schema and structure:
missing tag
non-numeric matched to numeric
extra element
wrong element order
too many array elements (element number in COBOL array is less than in XML array)
The COBOL sends an XML-EVENT structure to the handler procedure. This structure must not be defined in COBOL code, it will be added automatically by the compiler.
The EVENT-TYPE can be:
START-OF-ELEMENT
END-OF-ELEMENT
CONTENT-CHARACTERS
ATTRIBUTE-NAME
ATTRIBUTE-VALUE
START-OF-DOCUMENT
END-OF-DOCUMENT
The handler procedure checks against the EVENT-TYPE with IFs or an EVALUATE code block.
EXAMPLE FOR SYNTAX OF XML PARSE:
EXAMPLE FOR SIMPLE VALIDATION OF XML:
EXAMPLE FOR XML SCHEMA VALIDATION OF XML:
EXAMPLE FOR XML-EVENT STRUCTURE:
EXAMPLE FOR XML PARSE:
EXAMPLE FOR XML PARSE OF NESTED OBJECT AND ARRAY:
The XML GENERATE always generates indented format.
The WITH ATTRIBUTES forces the generator to inject the 05-level fields into the opening tag of the element as HTML attributes; lower-level fields will be used normally.
The SUPPRESS forces the generator to leave out empty fields.
The ENCODING clause defines the character coding of the output; default is UTF-8.
EXAMPLE FOR SYNTAX OF XML GENERATE:
EXAMPLE FOR XML GENERATE:
EXAMPLE FOR XML GENERATE WITH ATTRIBUTES: