Processing XML input

You can process XML input in a COBOL program by using the XML PARSE statement.

The XML PARSE statement is the COBOL language interface to either of two high-speed XML parsers. You use the XMLPARSE compiler option to select the appropriate parser for your application:
  • XMLPARSE(XMLSS) selects the z/OS® XML System Services parser.

    This option provides enhanced features such as namespace processing, validation of XML documents with respect to an XML schema, and conversion of text fragments to national character representation (Unicode UTF-16).

  • XMLPARSE(COMPAT) selects the XML parser that is built into the COBOL library.

    This option provides compatibility with XML parsing in Enterprise COBOL Version 3 and Version 4.

Processing XML input involves passing control between the XML parser and a processing procedure in which you handle parser events.

Use the following COBOL facilities to process XML input:

  • The XML PARSE statement to begin XML parsing and to identify the source XML document and the processing procedure.
    You can also use the following optional phrases of the XML PARSE statement:
    • ENCODING to specify the encoding of the XML document
    • VALIDATING to identify an XML schema against which the XML document is to be validated
  • The processing procedure to control the parsing, that is, receive and process XML events and associated document fragments, and return to the parser for continued processing
  • Special registers to exchange information between the parser and the processing procedure:
    • XML-CODE to receive the status of XML parsing and, in some cases, to return information to the parser
    • XML-EVENT to receive the name of each XML event from the parser
    • XML-INFORMATION provides a mechanism to easily determine whether an XML event is complete
    • XML-NTEXT to receive XML document fragments that are returned as national character data
    • XML-TEXT to receive document fragments that are returned as alphanumeric data
    • XML-NAMESPACE or XML-NNAMESPACE to receive a namespace identifier for a NAMESPACE-DECLARATION XML event, or for an element name or attribute name that is in a namespace
    • XML-NAMESPACE-PREFIX or XML-NNAMESPACE-PREFIX to receive a namespace prefix for a NAMESPACE-DECLARATION XML event, or for an element name or attribute name that is prefixed
  • The optional RETURNING NATIONAL phrase of the XML PARSE statement to indicate that the fragments of an XML document in an alphanumeric data item are to be converted to UTF-16 and returned to the processing procedure in the national special registers XML-NTEXT, XML-NNAMESPACE, and XML-NNAMESPACE-PREFIX

You can use the ENCODING, VALIDATING, and RETURNING NATIONAL phrases of the XML PARSE statement only if XMLPARSE(XMLSS) is in effect.

Link-edit consideration: COBOL programs that contain the XML PARSE statement must be link-edited with AMODE 31.

related concepts  
XML parser in COBOL