%XML options for the XML-SAX operation code

doc (default string)
The doc option indicates what the source operand of %XML contains.
  • string indicates that the source operand contains XML data
  • file indicates that the source operand contains an IFS file name
Figure 1. Example of the doc option:
   // In the following example, the first parameter
   // of %XML is the name of a file.  Option
   // "doc=file" must be specified.
   ifsfile = 'myfile.xml';
   opt = 'doc=file';
   XML-SAX %handler(hdlr:comm) %XML(ifsfile : opt);

   // In the following example, the first parameter
   // of %XML is an XML document.  Since the "doc"
   // option defaults to "string", no options are
   // necessary.
   xmldata = '<data><num>3</num></data>';
   XML-SAX %handler(hdlr:comm) %XML(xmldata);
ccsid (default job)
The ccsid option specifies the CCSID that the XML data should be returned in.
  • job indicates that the XML parser should return data in the job CCSID. This is the CCSID that the RPG compiler uses for character data in the program.
  • ucs2 indicates that the XML parser should return data in the UCS-2 CCSID of the module.
  • numeric value indicates that the XML parser should return the data in the specified CCSID. In this case, it is up to the RPG programmer to ensure that the data is handled correctly within the RPG program. The RPG compiler will assume that character data is in the job CCSID.
Figure 2. Example of the ccsid option:
   // In the following example, the data is to be
   // returned in the job ccsid.  Even though the
   // default for the "ccsid" option is "job", it
   // is valid to specify it explicitly.
   XML-SAX %handler(hdlr:comm) %XML(xmlString : 'ccsid=job');

   // In the following example, the data is to be
   // returned in UCS-2.
   opt = 'ccsid=ucs2';
   XML-SAX %handler(hdlr:comm) %XML(xmldata : opt);

   // In the following example, the data is to be
   // returned in UTF-8.  The handling procedure must
   // exercise caution to convert the data to some CCSID
   // that the program can handle, if the data is to be
   // used within the handling procedure.
   XML-SAX %handler(hdlr:comm) %XML(xmldata : 'ccsid=1208');

Note: For *XML_UCS2_REF and *XML_ATTR_UCS2_REF events, the data is always returned as a UCS-2 value independent of the ccsid option.