The new XML statement is used to read XML documents. The following two phrases must be entered to permit this; the third is optional:
What is to be done? (mandatory)
PARSE identifier-1
The XML document contained in data item identifier-1 is to be parsed.
Who should process the results of parsing? (mandatory)
PROCESSING PROCEDURE IS procedure-name-1 [ { THRU | THROUGH } procedure-name-2]
Each time an 'event' is detected by the parser while the XML statement is being executed, control is transferred to processing procedure procedure-name-1. If the last statement has been executed by procedure-name-1 or procedure-name-2, control automatically returns to the XML statement which is still active.
How should the statement be terminated? (optional)
[ON EXCEPTION imperative-statement-1]
[NOT ON EXCEPTION imperative-statement-2]
identifies additional statements which are possibly to be executed if parsing ends abnormally or normally.
The activities of XML statement, processing procedure for events and XML parse are restricted in time as follows:
In summary, the following must be taken into consideration in the case of the XML statement:
The XML document – precisely one – is contained in the specified data item.
The repeated switch between XML statement and processing procedure continues until one of the following situations occurs:
The entire XML document has been processed.
The processing procedure indicates that processing is to be terminated immediately.
An error is reported.
For documents which are not well-formed the sequential processing method means that the parser might possibly have initiated events before it finds the faulty place in the document.
The precise description of the event and the data associated with it are available to the processing procedure in special registers.
The complete document is parsed and processed by executing a single statement.
Existing [NOT] EXCEPTION phrases are not executed after each event, but just once after the entire XML statement has ended.