Processing XML input
You can process XML input in a COBOL program by using the XML
PARSE statement.
About this task
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 PARSEstatement to begin XML parsing and to identify the source XML document and the processing procedure.You can also use the following optional phrases of theXML PARSEstatement:ENCODINGto specify the encoding of the XML documentVALIDATINGto 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-CODEto receive the status of XML parsing and, in some cases, to return information to the parserXML-EVENTto receive the name of each XML event from the parserXML-INFORMATIONprovides a mechanism to easily determine whether an XML event is completeXML-NTEXTto receive XML document fragments that are returned as national character dataXML-TEXTto receive document fragments that are returned as alphanumeric dataXML-NAMESPACEorXML-NNAMESPACEto receive a namespace identifier for aNAMESPACE-DECLARATIONXML event, or for an element name or attribute name that is in a namespaceXML-NAMESPACE-PREFIXorXML-NNAMESPACE-PREFIXto receive a namespace prefix for aNAMESPACE-DECLARATIONXML event, or for an element name or attribute name that is prefixed
- The optional
RETURNING NATIONALphrase of theXML PARSEstatement 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 registersXML-NTEXT,XML-NNAMESPACE, andXML-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.
Accessing XML documents
Parsing XML documents
Handling XML PARSE exceptions
Terminating XML parsing
XMLPARSE (compiler option)
The encoding of XML documents
XML reference material
Extensible Markup Language (XML)