Handling errors in XML documents

Use these facilities to handle errors in your XML document:

  • Your processing procedure
  • The ON EXCEPTION phrase of your XML PARSE statement
  • Special register XML-CODE

When the XML parser detects an error in an XML document, it generates an XML exception event. The parser returns this exception event by passing control to your processing procedure along with the following information:

  • The special register XML-EVENT contains 'EXCEPTION'.
  • The special register XML-CODE contains the numeric exception code.
  • XML-TEXT contains the document text up to and including the point where the exception was detected.

If the value of the error code is within one of the following ranges:

  • 1-99
  • 100,001-165,535
  • 200,001-265,535

you might be able to handle the exception in your processing procedure and continue the parse. If the error code has any other nonzero value, the parse cannot continue. The exceptions for encoding conflicts (50-99 and 300-499) are signaled before the parse of the document is started. For these exceptions, XML-TEXT is either zero length or contains just the encoding declaration value from the document.

Exceptions in the range 1-49 are fatal errors according to the XML specification, therefore the parser does not continue normal parsing even if you handle the exception. However the parser does continue scanning for further errors until it reaches the end of the document or encounters an error that does not allow continuation. For these exceptions, the parser does not signal any further normal events, except for the END-OF-DOCUMENT event.

Use the following figure to understand the flow of control between the parser and your processing procedure. It illustrates how you can handle certain exceptions and how you use XML-CODE to identify the exception. The off-page connectors, such as Off-page flow-chart connector., connect the multiple charts in this chapter. In particular, C off-page connector. in the following figure connects to the chart XML CCSID exception flow control. Within this figure E off-page connector./ C off-page connector. serves both as an off-page and an on-page connector.

Figure 1. Control flow for XML exceptions
This image shows a flowchart for XML exceptions, as described in surrounding text.