COMPAT XML parser considerations

User modifications to the XML document during execution of the XML PARSE statement

In versions earlier than Enterprise COBOL V5, the COMPAT XML parser was actively in progress when the XML processing procedure was executing. In V5, any encoding conflicts are resolved and after that, the entire document is parsed, and the XML events are stored in a buffer. After the parse is terminated, the XML events are then presented from this buffer to your program by the PERFORM statement that executes the processing procedure. Thus, if the program modifies the XML document in the processing procedure code, the parser does not detect these modifications. However, in the implementation in earlier versions, those modifications such as correcting an end tag name to match the start tag name would be seen and acted on by the parser.

A limited number of continuable XML EXCEPTION events

For XML EXCEPTION events with XML-CODE values in the range 1-49, if you request continuation by setting XML-CODE to zero, the COMPAT XML parser checks only for further errors and does not present any further non-EXCEPTION XML events. When the V5 COMPAT XML parser continues after an EXCEPTION event, the parser does not expand the XML event buffer and thus might not present all the EXCEPTION events that would otherwise occur. The initial buffer size can accommodate a minimum of 8192 XML events and is expanded as necessary for non-EXCEPTION events.

Differences caused by LE condition handling

In versions earlier than Enterprise COBOL V5, the processing procedure was executed in a stack frame that is subordinate to the stack frame of the active XML parser. The processing procedure for the V5 COMPAT parser runs in the same stack frame as the rest of the COBOL program, after the XML parser has run to completion. This change has the following effects:
  • Previously, LE condition handlers that are registered in the XML processing procedure were not in effect after a COMPAT XML PARSE statement is terminated. In the V5 implementation, they remain in effect until unregistered.
  • Previously, a branching to an LE service resume point that is set outside the XML processing procedure terminated a COMPAT XML PARSE statement. In V5, the processing procedure must exit normally to terminate an XML PARSE statement. Otherwise, the already active XML PARSE statement causes a runtime error if either the program exits (IGZ0227S) or another XML PARSE statement is executed (IGZ0228S).

    The following program illustrates this difference. As described previously, it executes correctly on versions earlier than Enterprise COBOL V5, but it causes runtime errors IGZ0227S or IGZ0228S on Enterprise COBOL V5. After you uncomment the indicated statements in the XML processing procedure, the program runs without error on all versions.

    Process XMLPARSE(COMPAT)
    ****************************************************************
    ***  Function:                                               ***
    ***  Demonstate a difference between XML PARSE COMPAT on     ***
    ***  V3/V4 and V5 (or XMLSS on any version).                 ***
    ***                                                          ***
    ***  In V3/4, the logical branch out of the XML processing   ***
    ***  procedure by CEEMRCE terminates the XML PARSE. In V5,   ***
    ***  it does not, resulting in runtime messages such as:     ***
    ***    IGZ0227S There was an invalid attempt to end an       ***
    ***             XML PARSE statement.                         ***
    ***  when the program terminates (or attempts another parse).***
    ****************************************************************
     Identification division.
       Program-id. XMLMIGR1.
     Data division.
      Working-storage section.
       1 XML-document pic x(4) value '<x/>'.
       1 zer0 comp pic 9 value 0.
      Local-storage section.
       1 routine procedure-pointer.
       1 token pointer.
       1 ceesrp-data.
        2 resume-point comp pic s9(9).
        2 state pic x value 'I'.
       1 fdbk-code.
        2 condition-token-value.
          88 fdbk-code-zero value low-value.
         3 pic xx.
         3 msg-no comp pic s9(4).
         3 pic x(4).
        2 pic x(4).
     Procedure division.  Main section.
         Perform register-user-handler
         Call 'CEE3SRP' using resume-point fdbk-code
         Service label.
       Repeat.
         If state = 'I'
           XML parse XML-document processing procedure XML-proc
           Display 'Back from XML parse...'
           Go to Repeat
         Else
           If state = 'R'
             Display 'Resumed after exception; in mainline code.'
           End-if
           Perform unregister-user-handler
           Display 'Another XML parse (P), or exit (E)?'
           Accept state
           If state = 'P'
             Move '<y/>' to XML-document
             XML parse XML-document processing procedure XML-proc.
         Goback.
       Register-user-handler.
         Set routine to entry 'USERHDLR'
         Set token to address of ceesrp-data
         Call 'CEEHDLR' using routine token fdbk-code
         If fdbk-code-zero
           Display 'Registered exception handler successfully.'
         Else
           Display 'Failed to register exception handler!' msg-no
           Move 16 to return-code
           Stop run.
       Unregister-user-handler.
         Set routine to entry 'USERHDLR'
         Call 'CEEHDLU' using routine fdbk-code
         If fdbk-code-zero
           Display 'Unregistered exception handler successfully.'
         Else
           Display 'Failed to unregister exception handler!' msg-no
           Move 16 to return-code
           Stop run.
      XML-proc section.
         Display XML-event '{' XML-text '}'
         If XML-event = 'START-OF-DOCUMENT'
           Display 'XML parse in progress...'
           Move 1 to xml-code
           Go to xp-srp.
         If XML-event = 'START-OF-ELEMENT' and XML-text = 'x'
           Compute tally = 1 / zer0.
         Go to xp-exit.
       Xp-srp.
    *** Uncomment the next two lines to move the resume point to ***
    *** within the XML processing procedure, thus allowing the   ***
    *** XML PARSE statement to terminate normally and correctly. ***
    *    Call 'CEE3SRP' using resume-point fdbk-code
    *    Service label
         If state = 'R'
           Display 'Resumed after exception; still in XML-proc.'
           Move 'X' to state.
       Xp-exit.
         Continue.
     End program XMLMIGR1.
     
    ****************************************************************
    *** LE user condition handler, invoked when the fixed-point  ***
    *** divide exception occurs (system completion code S0C9).   ***
    ****************************************************************
     Identification division.
       Program-id. USERHDLR.
     Data division.
      Working-storage section.
       1 fdbk-code.
        2 condition-token-value pic x(8).
          88 fdbk-code-zero value low-value.
        2 pic x(4).
      Linkage section.
       1 ceesrp-data.
        2 resume-point comp pic s9(9).
        2 state pic x.
       1 token pointer.
       1 result comp pic s9(9).
        88 resume value 10.
       1 curr-cond pic x(12).
       1 new-cond pic x(12).
     Procedure division using curr-cond token result new-cond.
         Display 'LE condition handler called...'
         Set address of ceesrp-data to token
         Call 'CEEMRCE' using resume-point fdbk-code
         If not fdbk-code-zero display 'Unable to resume execution!'
         Else Set resume to true Move 'R' to state.
         Goback.
     End program USERHDLR.