× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Richard,

in basic it was simple, XMLCGI has the following code that sends the
generated XML in
the addr (pOClob( and size (szOClob) back to the browser:

// output
when status = RUN_CGI_OUTPUT;
// -----
// send header + end (LFLF)
respHead = 'Content-type: text/xml' + CRLF + CRLF + NULLTERM;
rn = writeIFS(1:%addr(respHead):strlen(%addr(respHead)));
// send return data
szOClob = strlen(pOClob);
rn = writeIFS(1:pOClob:szOClob);
status = RUN_CGI_FINISH;

I added a new parameter xFMT and changed the original code to:

// output
when status = RUN_CGI_OUTPUT;
status = RUN_CGI_FINISH;
szOClob = strlen(pOClob);

if xFMT <> '*json';

// ----- ORIGINAL XML

// send header + end (LFLF)
respHead = 'Content-type: text/xml' + CRLF + CRLF + NULLTERM;
rn = writeIFS(1:%addr(respHead):strlen(%addr(respHead)));
// send return data
rn = writeIFS(1:pOClob:szOClob);

else;

// ----- OUTPUT BY EXIT PROGRAM
// call exit program
xmlcgix2(pOClob:szOClob);

endif;

Then I made a little program (XMLCGIX2) that converts the XML result into
JSON
and then sends the new result to the browser:

* Standard powerEXT H-Spec's
/copy qsrc,pxapihdr General H-Spec's

* powerEXT API Connectors
/copy qsrc,pxapicgicn Basic HTTP connecter & Basic Services

d fieldName s 10a varying


* Program Entry
d PgmEntry pr extpgm('XMLCGIX2')
d *
d 10i 0

d PgmEntry pi
d pOClob *
d szOClob 10i 0

/free
clearSrvPgm();
setContent('text/html');
xmlReaderInz(pOClob:szOClob);
jsonNode('*object');
jsonNode('*boolean':'success':'true');
jsonNode('*array':'rows');
dow xmlReader = 0;
select;
when xmlGetNode = '%row';
jsonNode('*object');
when xmlGetNode = 'data' and xmlGetAttr = 'desc';
fieldName = xmlGetData;
when xmlGetNode = 'data' and xmlGetAttr = '';
if 0 <> %check('.-0123456789':xmlGetData)
or xmlGetData = '.'
or xmlGetData = '-'
or xmlGetData = '';
jsonNode('*string':fieldName:xmlGetData);
else;
jsonNode('*number':fieldName:xmlGetData);
endif;
when xmlGetNode = '/row';
jsonEndNode();
endsl;
enddo;
jsonEndNode();
jsonEndNode();
echoToClient();
return;
/end-free

If I should make a more generic solution I would probably not chose a xFMT
parameter and a fixed program name but pass a parameter with the exit
program name so I could have a number of exit programs that filter and/or
convert the result to whatever I chose without having to change the code
in XMLCGI.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.