Output by writer on CGI context. (tested under CGIDEV2 Apache instance on V6R1)
h dftactgrp(*no)
h actgrp('T_IFSXML')
h bnddir('IFSXML': 'QC2LE': 'CGI')
**********************************************************************************************
* *
* XMLIFS 1.0 sample program *
* *
* ifsxml_setWriter() sample. Output to HTML. *
* *
* ------------------------------------------------------------------------------------------ *
* *
* You must have QZHBCGI/*SRVPGM/QHTTPSVR (in this place assumed on bnddir 'CGI') *
* *
* Compile IFSXML module (or service program) and add it to a bind dir named 'IFSXML' before *
* compile this program. Usable from v5r2. *
* *
* ------------------------------------------------------------------------------------------ *
* *
* neditespas400.com / Cédric Chapuis *
* *
**********************************************************************************************
/copy QRPGLEINC,IFSXML
* -- Externals prototypes -------------------------------------------------
d QtmhWrStout...
d pr extProc('QtmhWrStout')
d data...
d * value
d len...
d 10i 0 const
d apiError...
d 8000a options(*varsize)
d CEETREC...
d pr extproc('CEETREC')
*-- Internals prototypes -------------------------------------------------
d fillingXML...
d pr
d hXml...
d value like(m_ifsxml_handle)
d iteration...
d 10u 0 const
d myWriter...
d pr
d hXml...
d value like(m_ifsxml_handle)
d dta...
d * value
d len...
d 10u 0 const
*-- Constants ------------------------------------------------------------
d CRLF...
d c x'0D25'
*-- Globals variables ----------------------------------------------------
* Handle of the XML document
d hXml...
d s like(m_ifsxml_handle)
d g_maxLen...
d s 10u 0 inz(1024)
d string...
d s 128a varying
D err ds qualified
D bytesProv 10i 0 inz(0)
D bytesAvail 10i 0 inz(0)
**********************************************************************************************
*
* Entry
*
**********************************************************************************************
/free
// Get a new handle
hXml = ifsxml_new();
// Set no formating
ifsxml_setPretty(hXml: IFSXML_NONE);
// Set "myWriter"
ifsxml_setWriter(hXml: %paddr(myWriter));
// HTML header
string = 'Status: 200' + CRLF
+ 'Content-type: text/xml'
+ CRLF + CRLF;
QtmhWrStout(%addr(string) + 2: %len(string): err);
// Set header (optional)
ifsxml_addXmlHeader(hXml: '1.0': 'UTF-8');
// Editing
fillingXML(hXml: 25);
// Free the handle
ifsxml_free(hXml);
// Close current activation group.
CEETREC();
*inlr = *on;
/end-free
*---------------------------------------------------------------------------------------------
*
* Reusable function for filling XML data
*
*---------------------------------------------------------------------------------------------
p fillingXML...
p b
d pi
d hXml_...
d value like(m_ifsxml_handle)
d iteration_...
d 10u 0 const
d i...
d s 5u 0
d j...
d s like(i)
/free
// Define the root name
ifsxml_setRootName(hXml_: 'ifsxml');
// Create elements
for i = 1 to iteration_;
ifsxml_openElement(hXml_: 'element' + %char(i));
// ...and attributes
for j = 1 to i;
ifsxml_addAttribute(hXml_: 'attribute' + %char(j)
: 'Value ' + %char(j));
endfor;
endfor;
// Return to the root level
ifsxml_closeElement(hXml_: '');
// Create elements
for i = 1 to iteration_;
ifsxml_addElement(hXml_: 'element' + %char(i): 'Value ' + %char(i));
endfor;
// Close the document and the file
ifsxml_close(hXml_);
/end-free
p e
*---------------------------------------------------------------------------------------------
*
* Writer called by callback. Push data to QtmhWrStout by segment of g_maxLen size.
*
*---------------------------------------------------------------------------------------------
p myWriter...
p b
d pi
d hXml_...
d value like(m_ifsxml_handle)
d dta_...
d * value
d len_...
d 10u 0 const
d i...
d s 10u 0
d j...
d s like(i)
d k...
d s like(i)
d dta_p...
d s *
/free
dta_p = dta_;
if len_ > g_maxLen;
j = len_ / g_maxLen;
for i = 1 to j;
QtmhWrStout(dta_p: g_maxLen: err);
dta_p += g_maxLen;
k += g_maxLen;
endfor;
k = len_ - k;
else;
k = len_;
endif;
if k > 0;
QtmhWrStout(dta_p: k: err);
endif;
/end-free
p e
Ouput
T_IFSXML05 sample ouput