Page 1 of 1

XML-SAX failed with error code 6

Posted: Tue Mar 25, 2025 7:47 am
by peder udesen
Yesterday I had an RPG-program where the XML-SAX command failed with error code 6.

After googling what this means, I found out that the cause was a character that couldn't
be converted from UTF-8 to EBCDIC. I think it was the "hat" ^
character that somebody had hit accidently.

This program is based on an article from Scott Klement in SystemINetwork from 14th May 2009
about XML-SAX. So it is fairly old.

xml-sax %handler(xmlHandler: ignoreMe) %XML(%trim( pFromstmf ) : 'doc=file');

My question is - is it possible to add code, so it replaces an invalid character with a blank
so I don't get an error?

Kind regards
Peder

Re: XML-SAX failed with error code 6

Posted: Tue Mar 25, 2025 4:02 pm
by jonboy49
If you mean has anything changed with XML-SAX that would help with this the answer is no - nothing I can think of.

Only thing I can think of is to do a scan/replace operation. But that will take time so If the failure is infrequent, better to trap the error and run the scan/replace before a retry.

Re: XML-SAX failed with error code 6

Posted: Thu Mar 27, 2025 9:44 am
by peder udesen
In the documentation for XML-SAX it is possible to specify that the data passed to
the XML-handler is in a certain CCSID. So it is possible to specify CCSID=1208 ( UTF-8 )

Code: Select all

P xmlHandler      B                               
D xmlHandler      PI            10i 0             
D   ignore                       1a               
D   event                       10i 0 value       
D   string                        *   value       
D   stringLen                   20i 0 value       
D   exceptionId                 10i 0 value       


D value           s          65535a   based(String) 
D ucs2val         s          16363c   based(String) 
Normally with a single based character in EBCDIC format you can extract the value with
%subst(value:1:stringLen);

And in case you use UCS-2 that is a double based character you can extract the value with
%subst( ucs2val : 1 : %div(stringLen:2) );

But what do you do with UTF-8 that varies from 1 to 4 bytes pers character?


What I'm looking for is to have a variable with a string in UTF-8 format that is then moved to an EBCDIC variable
undergoing a conversion. In the manual we are told that "The substitution character for alphanumeric data is x'3F'."
for the case that an UTF-8 character can not be translated to an EBCDIC character

Then we could do something like this:

EBCDIC_value = UTF8_value;
EBCDIC_value = %xlate(x'3F' : ' ' : EBCDIC_value ); // convert x'3F' to a blank.

Re: XML-SAX failed with error code 6

Posted: Tue Apr 08, 2025 6:32 am
by peder udesen
Does anybody have a good idea how to handle this?