Writing procedures to process XML

In your processing procedure, code statements to handle XML events.

For each event that the parser encounters, the parser passes information to the processing procedure in several special registers. Use the content of those special registers to populate COBOL data structures and to control the processing.

Examine the XML-EVENT special register to determine which event the parser passed to the processing procedure. XML-EVENT contains an event name, such as 'START-OF-ELEMENT'. Obtain the text associated with the event from the XML-TEXT or XML-NTEXT special register.

When used in nested programs, the XML special registers are implicitly defined as GLOBAL in the outermost program.

For additional details about the XML special registers, see the following table.

Table 1. Special registers used by the XML parser
Special register Implicit definition and usage Content
XML-EVENT1, 3

PICTURE X(30) USAGE DISPLAY VALUE SPACE

The name of the XML event
XML-CODE2

PICTURE S9(9) USAGE BINARY VALUE ZERO

An exception code or zero for each XML event
XML-TEXT1, 4 Variable-length elementary category alphanumeric item Text (corresponding to the event that the parser encountered) from the XML document if you specify an alphanumeric item for the XML PARSE identifier
XML-NTEXT1 Variable-length elementary category national item Text (corresponding to the event that the parser encountered) from the XML document if you specify a national item for the XML PARSE identifier
  1. You cannot use this special register as a receiving data item.
  2. The XML GENERATE statement also uses XML-CODE. Therefore, if you have an XML GENERATE statement in the processing procedure, save the value of XML-CODE before the XML GENERATE statement, and restore the saved value after the XML GENERATE statement.
  3. The content of this special register is encoded according to the setting of the CHAR compiler option (EBCDIC, NATIVE, or S390).
  4. The content of XML-TEXT has the encoding of the source XML document: ASCII or UTF-8 if the CHAR(NATIVE) compiler option is in effect; EBCDIC if CHAR(EBCDIC) is in effect.

Restrictions:

The compiler inserts a return mechanism after the last statement in each processing procedure.

Example: program for processing XML

related concepts    
XML events  
XML-CODE  
XML-TEXT and XML-NTEXT  

related tasks  
Terminating XML parsing  

related references  
CHAR
  
XML-EVENT (COBOL for AIX Language Reference)