CELSIUSDOM
This example program demonstrates the basic structure of an RPG program utilizing RPG-XML Suite to compose an XML request, call a remote web service, and parse the response XML with the DOM parser.
H DEBUG(*YES) DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)
/copy QRPGLECPY,RXSCB
/copy QRPGLETPL,CELSIUS
D Template PR
D p 65535A Varying
D gData S Like(RXS_Var1Kv_t)
D gCelsius S 10I 0
D gFahrenheit S 10I 0
D gXmlRequest S Like(RXS_Var64Kv_t)
D gXmlResponse S Like(RXS_Var64Kv_t)
D gXPath S Like(RXS_Var8Kv_t)
D ComposeDS DS LikeDS(RXS_ComposeDS_t)
D TransmitDS DS LikeDS(RXS_TransmitDS_t)
D RootDomDS DS LikeDS(RXS_ParseDOMDS_t)
D ErrorDS DS LikeDS(RXS_CatchThrowErrorDS_t)
/free
monitor;
gFahrenheit = 100;
exsr compose;
exsr transmit;
exsr parse;
RXS_ResetDS( ErrorDS : RXS_DS_TYPE_CATCHTHROWERROR );
ErrorDS.MessageId = 'RXS9897';
ErrorDS.MessageData = 'Celsius Temp: '
+ %trim ( %editc( gCelsius : '3' ) + '°');
ErrorDS.ThrowToCaller = RXS_YES;
RXS_Throw( ErrorDS );
on-error;
endmon;
*Inlr = *On;
begsr compose;
RXS_ResetDS( ComposeDS : RXS_DS_TYPE_COMPOSE );
ComposeDS.TemplateProcedure = %Paddr( Template );
RXS_StartComposeEngine( ComposeDS );
RXS_ComposeVariable( fahrenheit : %Char(gFahrenheit) );
RXS_ComposeSection( content );
gXmlRequest = RXS_GetComposeBuffer();
endsr;
begsr transmit;
RXS_ResetDS( TransmitDS : RXS_DS_TYPE_TRANSMIT );
TransmitDS.URI =
'http://www.w3schools.com/xml/tempconvert.asmx';
TransmitDS.HeaderSOAPAction =
'"http://www.w3schools.com/xml/FahrenheitToCelsius"';
TransmitDS.LogFile = '/tmp/celsius.txt';
TransmitDS.HeaderContentType = 'text/xml; charset=utf-8';
TransmitDS.RequestCcsid = RXS_CCSID_UTF8;
gXmlResponse = RXS_Transmit( gXmlRequest : TransmitDS );
endsr;
begsr parse;
RootDomDS = RXS_OpenDom( gXmlResponse );
gXPath =
RXS_XPath('/*:Envelope/*:Body/*:FahrenheitToCelsiusResponse' +
'/*:FahrenheitToCelsiusResult' );
gData = RXS_ParseDomToText( gXPath : RootDomDS );
RXS_CloseDom( RootDomDS );
gCelsius = %Int( gData );
endsr;
/end-free
P Template B
D PI
D p 65535A Varying
// Template RPG source was created from the actual template
// STMF using the following command:
// CRTRPGTPL STMF('/www/rxs/templates/geturi2.tpl')
// FILE(RXS3/QRPGLETPL) MBR(CELSIUS)
// The RPG Template source is copied from QRPGLETPL by using
// /copy once in the D-specs and again below.
/copy QRPGLETPL,CELSIUS
P E