IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

COBOL using XML Parser


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sat Dec 13, 2008 5:42 pm
Reply with quote

I'm processing the XML through program COBOL z/OS (I guess we use 3.4 compiler version). On this XML I have something called "encoding=utf-8" which is a lot of problems to process. The parser is out with xml-code=70 (exception) and I already attempting to change the codepage option using CODEPAGE(1208) but I got xml-code=320.

Looks like in COBOL 4 there are WITH ENCODING to be used in XML Parser but I have COBOL 3.4. Are there a way to use xml parser to processing this encoding using cobol 3.4 ?

Regards
Paulo
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sat Dec 13, 2008 6:13 pm
Reply with quote

utf-8 is essentially ASCII, upgraded for Unicode. The XML encoding is determined by whatever generated the XML; if you don't change the encoding there you're wasting your time.

If you convert the file from ASCII to EBCDIC, you may be able to change the encoding from utf-i to ebcdic-cp-us and be able to read it in COBOL. However, that's not a viable long term solution IMHO since you need to be handling the code as specified by the generator.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sat Dec 13, 2008 7:14 pm
Reply with quote

How can I convert the message from ASCII to EBCDIC to manipulate it in COBOL ?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sat Dec 13, 2008 7:37 pm
Reply with quote

Unix System Services command iconv will do the conversion, if the file is in Unix -- I'd probably OPUT it, convert it, and OGET it if this is a testing process underway.

If iconv isn't suitable, when you do the transfer do it as a text file.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sat Dec 13, 2008 9:05 pm
Reply with quote

It will be a problem. My program is called by a CICS transaction that passes a commonarea and XML DOCUMENT as parameters with encoding there.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sat Dec 13, 2008 9:29 pm
Reply with quote

In that case, you can process it using UTF-8 or get the encoding changed on the source side.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sat Dec 13, 2008 11:20 pm
Reply with quote

but using XML PARSE I got XML-CODE=70. I tried to use CODEPAGE compile option with CODEPAGE(1208) NSYMBOL(NATIONAL) and is getting XML-CODE=320.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Dec 14, 2008 12:39 am
Reply with quote

Hello,

You are changing "things" on the mainframe-side of the process. . . .

You need to have the file changed on the system that generates the file as Robert suggested.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sun Dec 14, 2008 1:00 am
Reply with quote

In that case, you can process it using UTF-8 or get the encoding changed on the source side.

How can I do that ?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Dec 14, 2008 2:21 am
Reply with quote

Hello,

Quote:
How can I do that ?
You may or may not be able to. . .

I believe that if you get the file changed before you try to work with it, most or all of the problems will be resolved. One concern i would have is that even if you get something working, there may be some surprise later.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sun Dec 14, 2008 3:20 am
Reply with quote

I have not done a lot of work on XML so I can't say 100% for sure what will work for you, but I find in the COBOL Language Reference manual section 6.2.41.3.2:
Quote:
When you parse ASCII XML documents, the document fragments passed to the processing procedure in special register XML-TEXT are encoded in ASCII. Because Enterprise COBOL operations such as move and comparison rely on EBCDIC encoding or on national characters for proper operation, you must convert the document fragments before using them. To do this, first convert from the ASCII code page of the XML document to national characters using the NATIONAL-OF intrinsic function. Then, if necessary, convert the result from national characters to EBCDIC using the DISPLAY-OF intrinsic function. You can do this without an explicit national data item, for example, MOVE FUNCTION DISPLAY-OF (FUNCTION NATIONAL-OF(XML-TEXT ascii-ccsid) ebcdic-ccsid) TO ebcdic-text.

You can reliably write ASCII XML fragments to a file or database without conversion.
I would try the recommended conversion
Code:
MOVE FUNCTION DISPLAY-OF (FUNCTION NATIONAL-OF(XML-TEXT 819) 1047) TO XML-EBCDIC-TEXT.
819 is the LATIN-1 ASCII code page ccsid and 1047 is the LATIN-1 EBCDIC code page ccsid.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sun Dec 14, 2008 7:30 pm
Reply with quote

After did the changes I got XML-CODE=317

317 The parser cannot determine the document encoding. The document might be damaged.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sun Dec 14, 2008 8:16 pm
Reply with quote

Going back to your original post, the 70 is listed in the Programming Guide as meaning
Quote:
| The basic document encoding was
| EBCDIC, and the CODEPAGE compiler
| option specified a supported EBCDIC
| code page, but the document encoding
| declaration did not specify a
| supported EBCDIC code page.

which tells me that the file was converted from ASCII to EBCDIC but the encoding within the document was not updated. Can you try moving this file from its source as a binary file rather than text to see if the 70 goes away?

Alternatively, you could recompile the program with CODEPAGE(819) and see if the 70 goes away.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Sun Dec 14, 2008 9:00 pm
Reply with quote

Now I got XML-CODE=73

73 The actual document encoding was EBCDIC, but neither the CODEPAGE compiler option nor the document encoding declaration specified a supported EBCDIC code page. The parser uses EBCDIC code page 1140 (USA, Canada, . . . Euro Country Extended Code Page).
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Dec 15, 2008 1:21 am
Reply with quote

OK, recompile without the codepage option and change the encoding= string in the file from utf-8 to EBCDIC; basically the problem you keep getting is that the encoding= name must match the actual file encoding. Your file does not match; it appears to be an EBCDIC file with encoding=utf-8 specified. You can either change the file encoding by changing the file (and I do not know how to recode it from EBCDIC to utf-8 without additional research), or change what is expected by changing the encoding= string within the file.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Mon Dec 15, 2008 5:17 pm
Reply with quote

I put EBCDIC in place of UTF-8 in the file, keep the MOVE FUNCTION DISPLAY OF with DBCS option (it is required when we use DISPLAY OF function) however, I got xml-code=317 again making move from ASCII to EBCDIC. Attempting to move from EBCDIC to ASCII I got xml-code=83.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Dec 15, 2008 6:43 pm
Reply with quote

The 83 is promising -- it indicates the XML parser recognizes the file as being ASCII but the encoding didn't match -- try encoding='iso8859-1' for this file since that would indicate Latin-I ASCII.

Also, note that error codes 1 to 99 are error codes that XML handles and supposedly allows you to continue; have you checked the output field with the 70 or 83 error codes?
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Mon Dec 15, 2008 6:57 pm
Reply with quote

I changed the file to be 'iso8859-1' and resubmit and got xml-code=317. How can I interpose the xml-code 70 or 83 in my program ?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Dec 15, 2008 7:25 pm
Reply with quote

You've hit the limits of my knowledge -- if there's anybody with XML expertise at your site, you need to talk over your problem with them. The 317 is not an error that can be continued; 70 or 83 allow you to set XML-CODE to zero and continue processing according to the manual.

The error codes you've posted are consistently encoding conflict errors -- where the file is EBCDIC and the encoding= option of XML does not reflect an EBCDIC encoding, or the file is ASCII and the encoding= option does not reflect an ASCII encoding. The difficulty is finding an encoding string (819 or iso8859-1 or whatever) that allows the ASCII file to be processed, or the EBCDIC file to be processed with encoding=1047 or whatever: EBCDIC would be better since the mainframe would allow you to view the output but getting it processed would be the first thing.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Dec 16, 2008 1:18 am
Reply with quote

Hello,

To return to an earlier part of the topic - it may be helpful to try re-creating the file and using this new file for continued testing. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 16, 2008 2:25 am
Reply with quote

OK, I looked at an old program I wrote a year and a half ago -- the data does not include any encoding=. So make sure your file is EBCDIC, remove the encoding= from the first line, and run your XMLPARSE again. This should get you past the XML error -- I got XML-CODE=0 by doing so.

If you absolutely have to have the encoding, make sure the file is in EBCDIC, check the compile listing for the CODEPAGE used, and set the encoding to that CODEPAGE -- I thought we used 1047 but found out 1140 is selected by looking at a compile output.
Back to top
View user's profile Send private message
pleonard

New User


Joined: 20 Sep 2006
Posts: 19

PostPosted: Tue Dec 16, 2008 2:36 am
Reply with quote

I tried this one too. In my last test I removed the total header from XML file but for both (with header and without encoding=utf-8) I got XML-CODE=-1. I'm not sure which is the encoding made to this file because it is obtained from another program (that generates this XML to me). Maybe this program can be messed up this file I'm not sure. Indeed my program is attempting to process a XML message and their encoding are different between them.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top