Reputation: 135
We are facing an issue where in the xml messages with the special characters like [· (0xB7), Ý (0xDD), ¨(0xA8)] are getting rejected, when they are actually XML valid characters. What we found is that are invalid characters for the default encoding that is assigned to a message, when not specified. We can avoid this, if we specifically add the encoding type to the top of the message. We used the UTF-8 encoding. So by adding "" to the very beginning of the XML message, the characters should then become valid characters. Below is the cobol code:
XML GENERATE RESPONSEDATA FROM ACCT
COUNT IN RESPONSEDATALL
WITH ENCODING 1208
WITH XML-DECLARATION
END-XML
But when we see the xml generated it consists of characters as shown below:
..Ì_%.ÎÁÊËÑ?>.......Á>Ä?ÀÑ>Å..UTF-8....
The expected output is that the below encoding bit should be added to the header.
<?xml version=“1.0” encoding=“utf-8”?>
So the issue is when this generated XML is parsed back again in another peice of code, it encouters an XML-EXCEPTION and backs out altogether with an exception message.
The question is is there some other peice of code or compile options which need to be added to make this xml valid?
Upvotes: 3
Views: 1196
Reputation: 1834
This is completely normal.
You are encoding the XML as UTF-8, however you are viewing the XML on the mainframe (which is EBCDIC). When your ISPF viewer open the XML file that you have created, it just interprets the hex values and tried to show you something. Because these values do not line up with the EBCDIC character set, it looks like garbage. If you FTP the file down to your computer, you will see that the XML is in fact the output you are looking for.
When you are parsing the XML, you actually have to do some something similar and specify the encoding that was used during the generate. The code below will parse a UTF-8 XML, and on exception, it will display the all of the XML up until the point of the exception occurred in EBCDIC so it is readable in the mainframe SYSOUT
XML PARSE WS-MY-XML
ENCODING 1208
PROCESSING PROCEDURE XXXX-PROCESS-XML
ON EXCEPTION
DISPLAY "EXCEPTION OCCURED: "
DISPLAY FUNCTION DISPLAY-OF (
FUNCTION NATIONAL-OF (
XML-TEXT 1208
)
1140
)
END-XML
EDIT: that being said, there still could be a legitimate error in your XML such as an illegal character. If the code I have posted also does work, FTP the XML and run it through an XML validator online to see where the fault is.
Upvotes: 2