View previous topic :: View next topic
|
Author |
Message |
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
Hi All,
I am trying to parse the below piece of XML code using the cobol built in xml parser and facing the
following exception798761(XRSN_MARKUP_INVALID - An incorrect character is found within markup).
Code: |
Input xml
<Name>
<FirstName>Jack</FirstName>
<LastName>Nicholson</LastName>
</Name>
|
The exception occurs while processing the End-of-Element </Name> tag and the error occurs at byte 2(i.e. /). Could someone help me in resolving the issue.
Strangely, if we pass the input as a single record it works fine.
Note:The program is using the XMLPARSE(XMLSS) compiler option. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Could the input data set have line numbers? |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
The input dataset holds the below mentioned data only.
Code: |
<Name>
<FirstName>Jack</FirstName>
<LastName>Nicholson</LastName>
</Name> |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Perhaps by the time you come to parsing it, that / isn't a /?
You say it works when it is a line of its own. Does i work when it is the second line? Third? If you rearrange those four lines, does another line get a message, or the output look in any way wrong?
We'd need to see the relevant code, including definitions. |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
The code works fine if the input is as below(i.e. the entire input is passed as single record)
Code: |
<Name><FirstName>Jack</FirstName<LastName>Nic</LastName</Name> |
The input dataset which holds the XML is a variable length file of maximum record length 250. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Code:
<Name><FirstName>Jack</FirstName<LastName>Nic</LastName</Name> |
If your data set is actually like this, I'm surprised it works since the </FirstName and </LastName are missing the terminating > symbol. If your data set is not as you have posted, then you have a serious problem with quality control of what you are posting and hence NOTHING you have posted could be relied upon to be accurate.
Have you used DISPLAY to display precisely what XML is parsing? The error message came out for a reason -- namely, the XML parser does not think you are giving it appropriate data. Without a DISPLAY to show what is being passed to the parser, you are merely guessing about what the data set contents look like to COBOL. |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
Sorry, I have missed out the terminating symbol for the last name tag in the above mentioned post. It is a typo.
I have used display statements and it displays the exception occurs while processing the end of element </Name>. Also, the error occurs at byte 2('/') which i came to know using display statement. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Quote: |
<Name>
<FirstName>Jack</FirstName>
<LastName>Nicholson</LastName>
</Name>
|
I fed that into an online XML parser and no issues were encountered.
My guess is an unprintable character somewhere in your input data.
Or you need something like "<?xml version="1.0" encoding="UTF-8"?>"
as your first statement. |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
I have included the following line as first record in the input dataset but still facing the exception
Code: |
"<?xml version="1.0" encoding="UTF-8"?>" |
Also, have used the below display statement to identify the error point
Code: |
Display 'parsing rec :' INREC(1:REC-LENGTH)
DISPLAY 'XML DOCUMENT ERROR ' XML-CODE
ADD 1 TO LENGTH OF XML-TEXT GIVING ERROR-POINT
DISPLAY "BYTE " ERROR-POINT " OF " XML-TEXT " IS BAD" |
The output of the above display statement is
Code: |
parsing rec :</Name>
XML DOCUMENT ERROR 0000798761
BYTE 002 OF < IS BAD |
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
if You get an error when You think that You are not doing anything wrong
see what happens when You KNOW that there is an ERROR
for example instead of
try
also display the source in HEX to see that the chars match ...
got burned too many times because of code page issues in the 3270 emulator |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
I have used the tag </Donald> instead of</Name> but still the same exception is thrown.
The Hex on value for the tag </Name> in the input dataset is given below
Code: |
</Name>
46D8986
C15145E |
|
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
The codepage compilation parameter which I am using is CODEPAGE(1140) |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Code: |
3029 XRSN_MARKUP_INVALID
An incorrect character is found within markup.
Action: Change the document to correct the error and retry. |
If this doesn't clue you then I suggest, communicate the problem to IBM support.
check this too. See if any compiler options affects the behavior. |
|
Back to top |
|
|
muralikrishnan_new
New User
Joined: 02 Jun 2013 Posts: 15 Location: India
|
|
|
|
Hi Murugan,
Sorry for the late response. I am just sharing the my piece of code. Hope it would help you.
a) It seems the XML-parse in cobol will work for only single string. Hence I tried to convert the input as mentioned below,
Code: |
<Name> <FirstName>Jack</FirstName><LastName>Nicholson</LastName> </Name>
|
b) I have read the file and formed each segment as single string using the String function.
Please find below the piece of code,
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. COBGG.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT I-INXML ASSIGN TO INXML
FILE STATUS IS WS-INXML-FS.
SELECT U-UTXML ASSIGN TO UTXML.
DATA DIVISION.
*-------------
FILE SECTION.
*-------------
FD I-INXML
RECORD IS VARYING FROM 1 TO 121 DEPENDING ON WS-REC-LT
RECORDING MODE IS V.
01 XML-TEST-DOC PIC X(121).
FD U-UTXML
LABEL RECORD STANDARD
RECORDING MODE F
BLOCK 0 RECORDS.
01 UTXML-REC.
02 FNAME PIC X(35) VALUE SPACES.
02 LNAME PIC X(35) VALUE SPACES.
WORKING-STORAGE SECTION.
*=========================================
01 WS-WV.
*--------
03 WS-INXML-FS PIC 9(02).
03 WS-INXML-EOF PIC X(01).
03 WS-XML-DOC PIC X(121) VALUE SPACES.
03 WS-XML-DATA PIC X(121) VALUE SPACES.
03 WS-XML-PPR-DATA PIC X(5000) VALUE SPACES.
03 WS-POINTER-VAL PIC S9(06).
03 WS-REC-LT PIC S9(03) COMP.
03 WS-CRT-TAG PIC X(20) VALUE SPACES.
03 WS-NAME-CNT PIC S9(09) PACKED-DECIMAL.
03 WS-TOT-NAME-CNT PIC S9(09) PACKED-DECIMAL.
03 WS-TLLY-CNT PIC S9(03) PACKED-DECIMAL.
03 WS-TLR-SPC-CNT PIC S9(03) PACKED-DECIMAL.
03 WS-LD-SPC-CNT PIC S9(03) PACKED-DECIMAL.
03 WS-TOT-SPC-CNT PIC S9(03) PACKED-DECIMAL.
03 WS-LTH-XML-VL PIC S9(03) PACKED-DECIMAL.
03 WS-STG-STT-POS PIC S9(03) PACKED-DECIMAL.
PROCEDURE DIVISION.
*-------------------
PERFORM START-XML-PARSE.
PERFORM PROCESS-XML-PARSE
UNTIL WS-INXML-EOF=HIGH-VALUES
PERFORM END-OF-XML-PARSE.
STOP RUN.
******************************************A-LEVEL*********** *****
START-XML-PARSE.
*-------------------
PERFORM INITIALIZE-PGM.
PERFORM OPEN-FILE.
PROCESS-XML-PARSE.
*-------------------
PERFORM PROC-XML-PARSE.
END-OF-XML-PARSE.
*-------------------
PERFORM CLOSE-FILE.
******************************************Z-LEVEL*********** *****
INITIALIZE-PGM.
*--------------
MOVE LOW-VALUES TO WS-INXML-EOF.
MOVE 1 TO WS-POINTER-VAL.
MOVE ZEROES TO WS-TOT-CNT.
MOVE ZEROES TO WS-TLLY-CNT.
MOVE ZEROES TO WS-NAME-TOT-CNT.
OPEN-FILE.
*--------------
OPEN INPUT I-INXML.
OPEN OUTPUT U-UTXML.
IF WS-INXML-FS = '00'
CONTINUE
ELSE
DISPLAY 'STATUS OPEN' WS-INXML-FS
STOP RUN
END-IF
CLOSE-FILE.
*----------------
CLOSE I-INXML
U-UTXML.
PROC-XML-PARSE.
*--------------------
MOVE SPACES TO WS-XML-DOC.
READ I-INXML INTO WS-XML-DOC
AT END
MOVE HIGH-VALUES TO WS-INXML-EOF
NOT AT END
PERFORM STAGE-XML-TEXT
END-READ.
IF WS-INXML-FS = '00'
CONTINUE
ELSE
DISPLAY'FILE STATUS' WS-INXML-FS
END-IF.
STAGE-XML-TEXT.
*----------------
MOVE ZEROES TO WS-TLLY-CNT.
INSPECT WS-XML-DOC TALLYING WS-TLLY-CNT FOR ALL 'NAME'
IF WS-TLLY-CNT > 0
ADD 1 TO WS-NAME-CNT
END-IF
IF WS-NAME-CNT > 0
PERFORM VALID-XML-DATA
END-IF
IF WS-NAME-CNT = 2
PERFORM XML-PARSE-DATA
MOVE SPACES TO WS-XML-PPR-DATA
MOVE SPACES TO WS-XML-DATA
MOVE ZEROES TO WS-NAME-CNT
MOVE 1 TO WS-POINTER-VAL
END-IF.
VALID-XML-DATA.
*-----------------
MOVE ZEROS TO WS-TLR-SPC-CNT
WS-LD-SPC-CNT
WS-TOT-SPC-CNT
WS-TLLY-CNT.
INSPECT FUNCTION REVERSE(WS-XML-DOC) TALLYING
WS-TLR-SPC-CNT FOR LEADING SPACES
INSPECT WS-XML-DOC TALLYING
WS-LD-SPC-CNT FOR LEADING SPACES
COMPUTE WS-TOT-SPC-CNT = WS-TLR-SPC-CNT +
WS-LD-SPC-CNT
END-COMPUTE
COMPUTE WS-LTH-XML-VL = LENGTH OF WS-XML-DOC -
WS-TOT-SPC-CNT
END-COMPUTE
COMPUTE WS-STG-STT-POS = WS-LD-SPC-CNT + 1
END-COMPUTE
STRING WS-XML-DOC(WS-STG-STT-POS:WS-LTH-XML-VL) DELIMITED
BY SIZE
INTO WS-XML-PPR-DATA
WITH POINTER WS-POINTER-VAL
XML-PARSE-DATA.
*--------------
XML PARSE WS-XML-PPR-DATA PROCESSING PROCEDURE NAMEPARSE
ON EXCEPTION
DISPLAY 'XML DOC ERROR ' XML-CODE
STOP RUN
END-XML.
NAMEPARSE.
*===========
EVALUATE XML-EVENT
WHEN 'END-OF-INPUT'
CONTINUE
WHEN 'START-OF-ELEMENT'
MOVE XML-TEXT TO WS-CRT-TAG
WHEN 'CONTENT-CHARACTERS'
PERFORM CONTENTELEMENT
WHEN 'END-OF-ELEMENT'
PERFORM ENDELEMENT
INITIALIZE WS-CRT-TAG
WHEN 'ERROR'
MOVE '1' TO ERR
WHEN 'EXCEPTION'
DISPLAY 'ZOEFPARSE:XML-EXCEPTION ' XML-CODE
END-EVALUATE.
WRITENAME.
*==========
WRITE UTXML-REC.
CONTENTELEMENT.
EVALUATE WS-CRT-TAG
WHEN 'FIRSTNAME'
MOVE XML-TEXT TO MSG-TYPE-CD
WHEN 'LASTNAME'
MOVE XML-TEXT TO OBJ-CD
END-EVALUATE.
ENDELEMENT.
EVALUATE XML-TEXT
WHEN 'NAME'
PERFORM WRITENAME
INITIALIZE UTXML-REC
END-EVALUATE.
|
let me know if you face any issues. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
Sorry for the late response. |
You did nothing to be sorry for and in fact you are helping him in a weeks time which is not really late btw you are not obligated to reply it is as and when you want to when you have time and if he were to be seriously needing help then he would have came back before you even could reply. |
|
Back to top |
|
|
rajesh1183
New User
Joined: 07 Jan 2008 Posts: 98 Location: Hyderabad
|
|
|
|
Can you try searching for invalid character using f p'.' in your XML piece... sometimes, while doing a copy-paste from some other source, invalid characters can creep in and can be in hidden mode. |
|
Back to top |
|
|
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
Thanks All. I appended the data to a single string variable and did the parsing. |
|
Back to top |
|
|
muralikrishnan_new
New User
Joined: 02 Jun 2013 Posts: 15 Location: India
|
|
|
|
Thank you for the update !! :-) |
|
Back to top |
|
|
|