Processing XML input
You can process XML input in a COBOL program by using the XML
PARSE
statement.
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 theXML PARSE
statement:ENCODING
to specify the encoding of the XML documentVALIDATING
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 parserXML-EVENT
to receive the name of each XML event from the parserXML-INFORMATION
provides a mechanism to easily determine whether an XML event is completeXML-NTEXT
to receive XML document fragments that are returned as national character dataXML-TEXT
to receive document fragments that are returned as alphanumeric dataXML-NAMESPACE
orXML-NNAMESPACE
to receive a namespace identifier for aNAMESPACE-DECLARATION
XML event, or for an element name or attribute name that is in a namespaceXML-NAMESPACE-PREFIX
orXML-NNAMESPACE-PREFIX
to receive a namespace prefix for aNAMESPACE-DECLARATION
XML event, or for an element name or attribute name that is prefixed
- The optional
RETURNING NATIONAL
phrase of theXML 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 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)