Hope someone can help me. I'm trying to use XML PARSE in Cobol. If one of my elements consists of CDATA and the program was compiled with XMLSS, i get the following error: 'EXCEPTION 000798761'. If compiled with COMPAT, I get error 'EXCEPTION 000000136', which according to the documentation reads: 'The parser found an invalid start of a comment or CDATA section in element content.'. Why can't there be a CDATA in a element? If someone can shed some light on the matter, I would appreciate it very much.
Below find all the info needed:
-Input XML (all in 1 line in a file called AGTTS.TV.TEMP):
<RegistrationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.astutefse.com/schemas/fsb-register/1.0">
<CarrierCode Reference="20111101">SLM</CarrierCode>
<Response ResultCode="0">FSB Response: GUID Already Used!<![CDATA[FSBReference]]></Response>
</RegistrationResponse>
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.astutefse.com/schemas/fsb-register/1.0">
<CarrierCode Reference="20111101">SLM</CarrierCode>
<Response ResultCode="0">FSB Response: GUID Already Used!<![CDATA[FSBReference]]></Response>
</RegistrationResponse>
JCL used to submit job (info most probably irrelevant):
//AGTXML EXEC PGM=AGTTIM
//STEPLIB DD DSN=BEMT.SL2,DISP=SHR
// DD DSN=TPDS.LINKLIB,DISP=SHR
//INFILE DD DSN=AGTTS.TV.TEMP3,DISP=SHR
//STEPLIB DD DSN=BEMT.SL2,DISP=SHR
// DD DSN=TPDS.LINKLIB,DISP=SHR
//INFILE DD DSN=AGTTS.TV.TEMP3,DISP=SHR
Code (only snippets):
*====================*
INPUT-OUTPUT SECTION.
*====================*
FILE-CONTROL.
SELECT INFILE ASSIGN TO INFILE.
*
***************
DATA DIVISION.
***************
*============*
FILE SECTION.
*============*
*
FD INFILE
BLOCK CONTAINS 0 CHARACTERS
RECORDING MODE IS F
LABEL RECORD IS STANDARD
DATA RECORD IS XML-DOCUMENT.
*
01 XML-DOCUMENT.
05 XML-DATA PIC X(27968).
*
EJECT
*=======================*
WORKING-STORAGE SECTION.
*=======================*
*
01 CURRENT-ELEMENT PIC X(40).
01 XML-DOCUMENT-LENGTH COMPUTATIONAL PIC 999.
*
01 REGISTRATION-RESPONSE.
05 CARRIER-CODE PIC X(3).
05 CARRIER-REF PIC 9(8).
05 RESPONSE-CODE PIC 9.
05 RESPONSE-DESCRIPTION PIC X(100).
05 FSB-REF-NR PIC 9(4).
05 REPRESENTATIVE OCCURS 1000 TIMES.
10 REP-ACTION PIC X(6).
*
EJECT
*
********************
PROCEDURE DIVISION.
********************
*===================*
A010-START SECTION.
*===================*
*
PERFORM A050-OPEN.
*
PERFORM A100-PROCESS.
*
PERFORM A900-CLOSING.
*
A010-END.
GOBACK.
EJECT
*==================*
A050-OPEN SECTION.
*==================*
OPEN INPUT INFILE.
MOVE SPACES TO XML-DATA.
A050-END.
EXIT.
EJECT
*=====================*
A100-PROCESS SECTION.
*=====================*
PERFORM A200-READ.
PERFORM A300-PARSE-XML.
A100-END.
EXIT.
EJECT
*==================*
A200-READ SECTION.
*==================*
READ INFILE.
A200-END.
EXIT.
EJECT
*=======================*
A300-PARSE-XML SECTION.
*=======================*
XML PARSE XML-DOCUMENT
PROCESSING PROCEDURE A400-XML-HANDLER
ON EXCEPTION
DISPLAY 'XML DOCUMENT ERROR ' XML-CODE
NOT ON EXCEPTION
DISPLAY 'XML DOCUMENT SUCCESSFULLY PARSED'
END-XML.
A300-END.
EXIT.
*=========================*
A400-XML-HANDLER SECTION.
*=========================*
EVALUATE XML-EVENT
* ==> ORDER XML EVENTS MOST FREQUENT FIRST
WHEN 'START-OF-ELEMENT'
DISPLAY 'START ELEMENT TAG: <' XML-TEXT '>'
MOVE XML-TEXT TO CURRENT-ELEMENT
WHEN 'CONTENT-CHARACTERS'
DISPLAY 'CONTENT CHARACTERS: <' XML-TEXT '>'
* ==> TRANSFORM XML CONTENT TO OPERATIONAL COBOL DATA ITEM...
EVALUATE CURRENT-ELEMENT
WHEN 'CarrierCode'
DISPLAY ' CONTENT OF CarrierCode IS ' XML-TEXT
END-EVALUATE
WHEN 'END-OF-ELEMENT'
DISPLAY 'END ELEMENT TAG: <' XML-TEXT '>'
MOVE SPACES TO CURRENT-ELEMENT
WHEN 'START-OF-DOCUMENT'
COMPUTE XML-DOCUMENT-LENGTH = FUNCTION LENGTH(XML-TEXT)
DISPLAY 'START OF DOCUMENT: LENGTH=' XML-DOCUMENT-LENGTH
' CHARACTERS.'
WHEN 'END-OF-DOCUMENT'
DISPLAY 'END OF DOCUMENT.'
WHEN 'VERSION-INFORMATION'
DISPLAY 'VERSION: <' XML-TEXT '>'
WHEN 'ENCODING-DECLARATION'
DISPLAY 'ENCODING: <' XML-TEXT '>'
WHEN 'STANDALONE-DECLARATION'
DISPLAY 'STANDALONE: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-NAME'
DISPLAY 'ATTRIBUTE NAME: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-CHARACTERS'
DISPLAY 'ATTRIBUTE VALUE CHARACTERS: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-CHARACTER'
DISPLAY 'ATTRIBUTE VALUE CHARACTER: <' XML-TEXT '>'
WHEN 'START-OF-CDATA-SECTION'
DISPLAY 'START OF CDATA: <' XML-TEXT '>'
WHEN 'END-OF-CDATA-SECTION'
DISPLAY 'END OF CDATA: <' XML-TEXT '>'
WHEN 'CONTENT-CHARACTER'
DISPLAY 'CONTENT CHARACTER: <' XML-TEXT '>'
WHEN 'PROCESSING-INSTRUCTION-TARGET'
DISPLAY 'PI TARGET: <' XML-TEXT '>'
WHEN 'PROCESSING-INSTRUCTION-DATA'
DISPLAY 'PI DATA: <' XML-TEXT '>'
WHEN 'COMMENT'
DISPLAY 'COMMENT: <' XML-TEXT '>'
WHEN 'EXCEPTION'
COMPUTE XML-DOCUMENT-LENGTH = FUNCTION LENGTH (XML-TEXT)
DISPLAY 'EXCEPTION ' XML-CODE ' AT OFFSET '
XML-DOCUMENT-LENGTH '.'
WHEN OTHER
DISPLAY 'UNEXPECTED XML EVENT: ' XML-EVENT '.'
END-EVALUATE.
A400-END.
EXIT.
*==================*
A900-CLOSING SECTION.
*==================*
CLOSE INFILE.
A900-END.
EXIT.
INPUT-OUTPUT SECTION.
*====================*
FILE-CONTROL.
SELECT INFILE ASSIGN TO INFILE.
*
***************
DATA DIVISION.
***************
*============*
FILE SECTION.
*============*
*
FD INFILE
BLOCK CONTAINS 0 CHARACTERS
RECORDING MODE IS F
LABEL RECORD IS STANDARD
DATA RECORD IS XML-DOCUMENT.
*
01 XML-DOCUMENT.
05 XML-DATA PIC X(27968).
*
EJECT
*=======================*
WORKING-STORAGE SECTION.
*=======================*
*
01 CURRENT-ELEMENT PIC X(40).
01 XML-DOCUMENT-LENGTH COMPUTATIONAL PIC 999.
*
01 REGISTRATION-RESPONSE.
05 CARRIER-CODE PIC X(3).
05 CARRIER-REF PIC 9(8).
05 RESPONSE-CODE PIC 9.
05 RESPONSE-DESCRIPTION PIC X(100).
05 FSB-REF-NR PIC 9(4).
05 REPRESENTATIVE OCCURS 1000 TIMES.
10 REP-ACTION PIC X(6).
*
EJECT
*
********************
PROCEDURE DIVISION.
********************
*===================*
A010-START SECTION.
*===================*
*
PERFORM A050-OPEN.
*
PERFORM A100-PROCESS.
*
PERFORM A900-CLOSING.
*
A010-END.
GOBACK.
EJECT
*==================*
A050-OPEN SECTION.
*==================*
OPEN INPUT INFILE.
MOVE SPACES TO XML-DATA.
A050-END.
EXIT.
EJECT
*=====================*
A100-PROCESS SECTION.
*=====================*
PERFORM A200-READ.
PERFORM A300-PARSE-XML.
A100-END.
EXIT.
EJECT
*==================*
A200-READ SECTION.
*==================*
READ INFILE.
A200-END.
EXIT.
EJECT
*=======================*
A300-PARSE-XML SECTION.
*=======================*
XML PARSE XML-DOCUMENT
PROCESSING PROCEDURE A400-XML-HANDLER
ON EXCEPTION
DISPLAY 'XML DOCUMENT ERROR ' XML-CODE
NOT ON EXCEPTION
DISPLAY 'XML DOCUMENT SUCCESSFULLY PARSED'
END-XML.
A300-END.
EXIT.
*=========================*
A400-XML-HANDLER SECTION.
*=========================*
EVALUATE XML-EVENT
* ==> ORDER XML EVENTS MOST FREQUENT FIRST
WHEN 'START-OF-ELEMENT'
DISPLAY 'START ELEMENT TAG: <' XML-TEXT '>'
MOVE XML-TEXT TO CURRENT-ELEMENT
WHEN 'CONTENT-CHARACTERS'
DISPLAY 'CONTENT CHARACTERS: <' XML-TEXT '>'
* ==> TRANSFORM XML CONTENT TO OPERATIONAL COBOL DATA ITEM...
EVALUATE CURRENT-ELEMENT
WHEN 'CarrierCode'
DISPLAY ' CONTENT OF CarrierCode IS ' XML-TEXT
END-EVALUATE
WHEN 'END-OF-ELEMENT'
DISPLAY 'END ELEMENT TAG: <' XML-TEXT '>'
MOVE SPACES TO CURRENT-ELEMENT
WHEN 'START-OF-DOCUMENT'
COMPUTE XML-DOCUMENT-LENGTH = FUNCTION LENGTH(XML-TEXT)
DISPLAY 'START OF DOCUMENT: LENGTH=' XML-DOCUMENT-LENGTH
' CHARACTERS.'
WHEN 'END-OF-DOCUMENT'
DISPLAY 'END OF DOCUMENT.'
WHEN 'VERSION-INFORMATION'
DISPLAY 'VERSION: <' XML-TEXT '>'
WHEN 'ENCODING-DECLARATION'
DISPLAY 'ENCODING: <' XML-TEXT '>'
WHEN 'STANDALONE-DECLARATION'
DISPLAY 'STANDALONE: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-NAME'
DISPLAY 'ATTRIBUTE NAME: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-CHARACTERS'
DISPLAY 'ATTRIBUTE VALUE CHARACTERS: <' XML-TEXT '>'
WHEN 'ATTRIBUTE-CHARACTER'
DISPLAY 'ATTRIBUTE VALUE CHARACTER: <' XML-TEXT '>'
WHEN 'START-OF-CDATA-SECTION'
DISPLAY 'START OF CDATA: <' XML-TEXT '>'
WHEN 'END-OF-CDATA-SECTION'
DISPLAY 'END OF CDATA: <' XML-TEXT '>'
WHEN 'CONTENT-CHARACTER'
DISPLAY 'CONTENT CHARACTER: <' XML-TEXT '>'
WHEN 'PROCESSING-INSTRUCTION-TARGET'
DISPLAY 'PI TARGET: <' XML-TEXT '>'
WHEN 'PROCESSING-INSTRUCTION-DATA'
DISPLAY 'PI DATA: <' XML-TEXT '>'
WHEN 'COMMENT'
DISPLAY 'COMMENT: <' XML-TEXT '>'
WHEN 'EXCEPTION'
COMPUTE XML-DOCUMENT-LENGTH = FUNCTION LENGTH (XML-TEXT)
DISPLAY 'EXCEPTION ' XML-CODE ' AT OFFSET '
XML-DOCUMENT-LENGTH '.'
WHEN OTHER
DISPLAY 'UNEXPECTED XML EVENT: ' XML-EVENT '.'
END-EVALUATE.
A400-END.
EXIT.
*==================*
A900-CLOSING SECTION.
*==================*
CLOSE INFILE.
A900-END.
EXIT.
This is the output I receive:
START OF DOCUMENT: LENGTH=968 CHARACTERS.
START ELEMENT TAG: <RegistrationResponse>
ATTRIBUTE NAME: <xmlns:xsi>
ATTRIBUTE VALUE CHARACTERS: <http://www.w3.org/2001/XMLSchema-instance>
ATTRIBUTE NAME: <xmlns:xsd>
ATTRIBUTE VALUE CHARACTERS: <http://www.w3.org/2001/XMLSchema>
ATTRIBUTE NAME: <xmlns>
ATTRIBUTE VALUE CHARACTERS: <http://www.astutefse.com/schemas/fsb-register/1.0>
START ELEMENT TAG: <CarrierCode>
ATTRIBUTE NAME: <Reference>
ATTRIBUTE VALUE CHARACTERS: <20111101>
CONTENT CHARACTERS: <SLM>
CONTENT OF CarrierCode IS SLM
END ELEMENT TAG: <CarrierCode>
START ELEMENT TAG: <Response>
ATTRIBUTE NAME: <ResultCode>
ATTRIBUTE VALUE CHARACTERS: <0>
CONTENT CHARACTERS: <FSB Response: GUID Already Used!>
EXCEPTION 000000136 AT OFFSET 289.
XML DOCUMENT ERROR 000000136
START ELEMENT TAG: <RegistrationResponse>
ATTRIBUTE NAME: <xmlns:xsi>
ATTRIBUTE VALUE CHARACTERS: <http://www.w3.org/2001/XMLSchema-instance>
ATTRIBUTE NAME: <xmlns:xsd>
ATTRIBUTE VALUE CHARACTERS: <http://www.w3.org/2001/XMLSchema>
ATTRIBUTE NAME: <xmlns>
ATTRIBUTE VALUE CHARACTERS: <http://www.astutefse.com/schemas/fsb-register/1.0>
START ELEMENT TAG: <CarrierCode>
ATTRIBUTE NAME: <Reference>
ATTRIBUTE VALUE CHARACTERS: <20111101>
CONTENT CHARACTERS: <SLM>
CONTENT OF CarrierCode IS SLM
END ELEMENT TAG: <CarrierCode>
START ELEMENT TAG: <Response>
ATTRIBUTE NAME: <ResultCode>
ATTRIBUTE VALUE CHARACTERS: <0>
CONTENT CHARACTERS: <FSB Response: GUID Already Used!>
EXCEPTION 000000136 AT OFFSET 289.
XML DOCUMENT ERROR 000000136