Question about XML-SAX and option ccsid=ucs2

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
peder udesen
Posts: 30
Joined: Thu Jul 29, 2021 8:00 am

Question about XML-SAX and option ccsid=ucs2

Post by peder udesen »

Hi Scott

Based on an article in SystemINetwork on 14th May 2009 from you we have coded a program to reveive
and proces XML-files using the XML-SAX function.

In the xmlHandler procedure there is a select - endsl structure like this:

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)       
.
.
.

select; 
when event = *XML_START_DOCUMENT;     
.
.
when event = *XML_START_ELEMENT;                          
   depth += 1;                                            
   if depth = 1;                                          
      stackname(depth) = '/' + %subst(value:1:stringLen); 
   else;                                                  
      stackname(depth) = stackname(depth-1) + '/'         
                       + %subst(value:1:stringLen);       
   endif;                                                 
   stackval(depth)  = '';                                 
  
 when event = *XML_ATTR_NAME;                        
   depth += 1;                                      
   stackname(depth) = stackname(depth-1) + '/@'     
                    + %subst(value:1:stringLen);    
   stackval(depth) = '';                            
                                                    
when event = *XML_END_ELEMENT                       
.
.
when event = *XML_CHARS                                    
  or event = *XML_PREDEF_REF                               
  or event = *XML_ATTR_CHARS                               
  or event = *XML_ATTR_PREDEF_REF;                         
   stackval(depth) += %subst(value:1:stringLen);           
                                                           
when event = *XML_UCS2_REF                                 
  or event = *XML_ATTR_UCS2_REF;                           
   stackval(depth) += %char(%subst( ucs2val : 1            
                           : %div(stringLen:2) ));         
endsl;                                                     
When executing the XML-SAX function there is a possibility to specify some options. Among others a "ccsid=ucs2".
This would cause this event *XML_UCS2_REF or *XML_ATTR_UCS2_REF to happen and convert the value in ucs2val
to be converted from ucs2 to ebcdic and saved in stackval.
So far so good.

But what about the *XML_START_ELEMENT and *XML_ATTR_NAME ?
Aren't they also in ucs2 format?

But here it looks like they are returned in the jobs ccsid. In this case EBCDIC.

Is it so so if you specify the option "ccsid=ucs2" then the data are returned in ucs2 format but
the element and the attribut-name is returned in ebcdic?

Kind regards
Peder Udesen
Scott Klement
Site Admin
Posts: 958
Joined: Sun Jul 04, 2021 5:12 am

Re: Question about XML-SAX and option ccsid=ucs2

Post by Scott Klement »

no... *XML_UCS2_REF and *XML_ATTR_UCS2_REF are always in UCS-2, it doesn't matter what you specify for the ccsid option. These are for references in the document, such as &#263a; because they are specified in unicode, whenever one appears, it must always be returned to you in unicode, it doesn't matter what the ccsid option is set to.

When you have ccsid=ucs2, all data thats returned to your program should be in UCS-2.
Post Reply