Example: parsing a simple document

This example shows the flow of events and the contents of special register XML-TEXT that result from the parsing of a simple XML document.

Assume that the COBOL program contains the following XML document in data item Doc:


<?xml version="1.0"?><msg type="short">Hello, World!</msg>

The following code fragment shows an XML PARSE statement for parsing Doc, and a processing procedure, P, for handling the XML events:


XML Parse Doc
   Processing procedure P
   . . .
P. Display XML-Event XML-Text.

The processing procedure displays the content of XML-EVENT and XML-TEXT for each event that the parser signals during parsing. The following table shows the events and the text.

Table 1. XML events and special registers
XML-EVENT XML-TEXT
START-OF-DOCUMENT  
VERSION-INFORMATION 1.0
START-OF-ELEMENT msg
ATTRIBUTE-NAME type
ATTRIBUTE-CHARACTERS short
CONTENT-CHARACTERS Hello, World!
END-OF-ELEMENT msg
END-OF-DOCUMENT  

Related concepts    
XML events  
XML-TEXT and XML-NTEXT