[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
parsing help
I have HTTPAPI and EXPAT loaded. I have attached a program I used from
example 17. I call a web service and I am writing the return xml to the
IFS /tmp folder. This all works YAiii!
But for some reason I am stuck trying to parse the daggone return XML
to my array.[ or even a field] UGHHH! Can someone help push me in the
right direction? I looked at CHARDATA1 in the EXPAT examples and I
kinda understand it but....hmmmm
how do I pull this in?
HeLP
Donnie Barrow
iSeries Consultant
513.709.0370
H*DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')
H BNDDIR('HTTPAPI':'QC2LE')
********************************************************************
?****** ******
?******* Program Name - PCA001CNM *******
?****** Description - Next Gen: P&A Web Service ******
?***** Created On - Nov 7, 2014 *****
?**** Created By - Donnie Barrow ****
?**** ****
?***** This program sends an XML request to SFD for *****
?***** Price and Availability and writes reponse XML *****
?***** to the IFS. program will then parse the data *****
?***** via EXPAT and return data to MAX. *****
?****** ******
*******************************************************************
*******************************************************************
* Data Definition Section *
*******************************************************************
* CST Master Item Crossreference
fCSTMIXL1 IF E K Disk
*
??*
??* Data Structure definitions
??*
D PCA001CNSM PR ExtPgm('PCA001CNSM')
D DSRqHdrA likeds(DSRqhdr)
D DSRqHdrB likeds(DSRqHdr2)
D PCAITEM1 likeds(RqItem1)
D DSRqHdrC likeds(DSRqHdr3)
D PCAITEM2 likeds(RqItem2)
D HomeCount 10I 0
D HomeCount2 10I 0
D PCACount 10I 0
D rtnList likeds(PCAOUT) dim(200) SRSITMAVL)
D PCA001CNSM PI
D DSRqHdrA likeds(DSRqhdr)
D DSRqHdrB likeds(DSRqHdr2)
D PCAITEM1 likeds(DSRqItm1)
D DSRqHdrC likeds(DSRqHdr3)
D PCAITEM2 likeds(DSRqItm2)
D HomeCount 10I 0
D HomeCount2 10I 0
D PCACount 10I 0
D rtnList likeds(PCAOUT) dim(200)
??*
D SaveEmbed PR
D embfile 50a varying
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 32767A varying const
D attrs * dim(32767)
D const options(*varsize)
D embedded PR
D PCAOUT41 likeds(PCAOUT) dim(200)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 32767A varying const
D attrs * dim(32767)
D const options(*varsize)
D X 10I 0 value
D CNVITEM PR Extpgm('CNVITEM')
D PCAOUTC1 likeds(PCAOUT)
??* PCA Request Header
d DSRqHdr E DS extname(PCAREQH)
d prefix(I_)
??* PCA Request Header 2
d DSRqHdr2 E DS extname(PCAREQH2)
d prefix(I1)
??* PCA Request Item1
d DSRqItm1 E DS extname(PCAITEM)
d prefix(I1)
d qualified
d* dim(200)
??* PCA Request Header Transfer
d DSRqHdr3 E DS extname(PCAREQH2)
d prefix(I2)
??* PCA Request Item2
d DSRqItm2 E DS extname(PCAITEM)
d prefix(I2)
d qualified
d* dim(200)
??* PCA Response- Item Availability
d DSRsItmAvl E DS extname(ITMAVAIL)
d prefix(O_)
??* PCA Response- Item Availability
d RQItem1 DS qualified based(@)
d I1itemid 27a ss.999999
d I1qty 11p 3 ss.999999
d I1qtyuom 3a
d I1prcuom 3a
d RQItem2 DS qualified based(@)
d I2itemid 27a ss.999999
d I2qty 11p 3 ss.999999
d I2qtyuom 3a
d I2prcuom 3a
??* PCA Response- Item Availability
d PCAOUT DS qualified based(@)
d itemid 27a ss.999999
d desc 31a ss.999999
d divid 4a ss.999999
d sysid 2a ss.999999
d store 2a ss.999999
d strnme 10a ss.999999
d incrm 10s 0 ss.999999
d mnpur 10s 0 ss.999999
d prtyp 2a ss.999999
d qtybo 10s 0 ss.999999
d qtyoh 10s 0 ss.999999
d qtyoo 10s 0 ss.999999
d qtyrs 10s 0 ss.999999
d stuom 2a ss.999999
d hunit 10s 0 ss.999999
d xunit 10s 0 ss.999999
d xcotm 10s 0 ss.999999
d xfday 10s 0 ss.999999
d xfflg 1a ss.999999
d stmsg 30A ss.999999
d excst 13s 5 ss.999999
d exfcst 13s 5 ss.999999
d sts1 1A ss.999999
d certyp 1A ss.999999
d ds
d SendTime z ccyy-mm-dd-hh.mm.
d timstp99x 26 overlay(SendTime) ss.999999
/copy httpapi_h
/copy ifsio_h
d SDS
d P#pgm *Proc
d P#status *Status
d Pstatus 11 15s 0
d P#job 244 253
d P#user 254 263
d P#date 270 275 0
d P#time 282 287 0
??*
??* Named constants definitions
d AppName c 'PriceCostAndAvailability'
d ReqService c 'PriceCostAndAvailability'
d AppClass c 'CA'
d ReqSystemID c 'X'
d SOAUSER c 'SOAUSER'
d CRLF c x'0D25'
Ddepth S 10I 0
Dname S 1024A
Dpath S 24576A
Dvalue S 32767A
Dattrs S * dim(32767)
D* const options(*varsize)
D SOAP 32767A varying
D HDIV s 32767A varying
D Requester s 32767A varying
D rc s 10I 0
D fd s 10I 0
D soapfile s 50a varying
D embfile s 50a varying
D wait s 1A
D X S 10I 0
D Y S 10I 0
D Z S 10I 0
D I1TemID S 27A
D I2TemID S 27A
D Sndtime1 S 26A
D basic S 1N
D digest S 1N
D realm S 124A
D userid S 50A
D pass S 50A
D err S 10I 0
d $action S 1A
/free
//Move in the parms from the calling program and process
Dsrqhdr = dsRqhdrA;
Dsrqhdr2 = dsRqhdrB;
Dsrqhdr3 = dsRqhdrC;
Dsrqitm1 = PCAitem1;
Dsrqitm2 = PCAItem2;
SendTime = %TIMESTAMP();
Sndtime1 = %trim(%char(SendTime));
//Check the Cross reference file.
//x=1;
//dow x<=HomeCount;
if dsrqitm2.I2ITemID <> *blanks;
Setll dsrqitm2.I2ITEMID CSTMIXL1;
Reade dsrqitm2.I2ITEMID CSTMIXL1;
If not %eof or %found;
dsrqitm1.I1itemID = CSTMPC;
Else;
//Insert Error, reset parms and return
//CLEAR ALL;
//*inlr = *on;
//return;
Endif;
Endif;
//x=x+1;
//enddo;
//Turn on Debugging and Strip Out CRLF on Return XML
http_debug(*ON);
http_XmlStripCRLF(*ON);
//Build the Soap request Header
//Requester =
SOAP =
'<?xml version="1.0"?>' +crlf
+'<soapenv:Envelope xmlns+
:vrt="http://esbprd.veritivcorp.com+
/VrtvPCA/SOA/vrtvPriceCostAvailability"' +crlf
+'xmlns:soapenv="http://schemas.xmlsoap.org/+
soap/envelope/">' +crlf
//+'xmlns:vrt="http://esbprd.veritivcorp.com+
// /VrtvPCA/SOA/vrtvPriceCostAvailability">' +crlf
//<soapenv:Envelope xmlms:vrt="http://esbprd.veritivcorp.com+
///VrtvPCA/SOA/vrtvPriceCostAvailability"' +crlf
//xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +crlf
+' <soapenv:Header/>' +crlf
+' <soapenv:Body>' +crlf
+' <vrt:vrtvWrpPCA>' +crlf
+' <uniEnvelope>' +crlf
+' <header>' +crlf
+' <requester formerResponse="?" reuseTransactionID="?">' +crlf
+' <applicationName>'+AppName+'</applicationName>' +crlf
+' <requestedService>'+ReqService+'</requestedService>' +crlf
+' <applicationClass>'+AppClass+'</applicationClass>' +crlf
+' <applicationInstance>??</applicationInstance>' +crlf
//<ApplicationInstanceType>?</ApplicationInstanceType>' +crlf
//<Version>?</Version>' +crlf
//<authenticationUserID>'+SOAUSER+'</authenticationUserID>' +crlf
+' <requestedByUserID>'+SOAUSER+'</requestedByUserID>' +crlf
+' <transactionId>??</transactionId>' +crlf
+' <requestedSystemId>'+ReqSystemID+'</requestedSystemId>' +crlf
+' <sendTimeStamp>'+SndTime1+'</sendTimeStamp>' +crlf
//<receiveTimeStamp>?</receiveTimeStamp>' +crlf
+' <docId1>?</docId1>' +crlf
+' <docId2>?</docId2>' +crlf
//<aSynchronous>?</aSynchronous>' +crlf
//<responseInfo/replyUrl>?</responseInfo/replyUrl>' +crlf
//<status>?</status>' +crlf
+' </requester>' +crlf
+' </header>' +crlf
+'<body>' +crlf
+' <pcaRequestMain>' +crlf
//+'<StoreID>'+%trim(I_StoreID)+'</StoreID>' +crlf
//+'<CustomerID>'+%trim(%char(I_Custmr))+'</CustomerID>' +crlf
//+'<FutureQtyRequiredFlag>'+%trim(I_FQRF)+
// '</FutureQtyRequiredFlag>' +crlf
+'<TransferProcessFlag>'+%trim(I_XFPRFL)+
'</TransferProcessFlag>' +crlf
+'<ReturnType>'+%trim(I_RTNTYP)+'</ReturnType>' +crlf;
//------------------------------------------------------------
// write the Home Division List XML
//------------------------------------------------------------
x=1;
//dow x <= HomeCount;
SOAP = SOAP
+'<HomeDivisionList>' +crlf
+'<SystemID>'+%trim(I1systmID)+'</SystemID>' +crlf
+'<DivisionID>'+%trim(I1DivID)+'</DivisionID>' +crlf
+' </HomeDivisionList>' +crlf;
// <TransferItemLst>' +crlf;
// <ItemDetailList>' +crlf;
// retrieve the items matching the stsID and Div
//y=1;
//dow y<= HomeCount;
//if I1systmID = I2systmID;
//SOAP = SOAP
//+' <ItemDetail>' +crlf;
//SOAP = SOAP
//+' <ItemID>'+%trim(dsrqitm1.i1itemID)+'</ItemID>' +crlf
//+' </ItemDetail>' +crlf;
//endif;
//y=y+1;
//enddo;
//SOAP = SOAP
//+' </ItemDetailList>' +crlf
//+'</HomeDivisionList>' +crlf;
//x=x+1;
//enddo;
//------------------------------------------------------------
// write the transfer Division List XML
//------------------------------------------------------------
//x=1;
//dow x <= HomeCount2;
SOAP = SOAP
+'<TransferItemLst>' +crlf
+' <TransferItem>' +crlf
+'<SystemID>'+%trim(I2Systmid)+'</SystemID>' +crlf
+'<DivisionID>'+%trim(I2DivID)+'</DivisionID>' +crlf
+' <ItemDetailList>' +crlf;
// retrieve the items matching the stsID
//y=1;
//dow y<= HomeCount;
//if I2systmid = I1systmid;
SOAP = SOAP
+' <ItemDetail>' +crlf;
SOAP = SOAP
+' <ItemID>'+%trim(dsrqitm2.i2itemid)+'</ItemID>' +crlf
+' </ItemDetail>' +crlf;
//endif;
//y=y+1;
//enddo;
SOAP = SOAP
+' </ItemDetailList>' +crlf
+' </TransferItem>' +crlf
+'</TransferItemLst>' +crlf;
//x=x+1;
//enddo;
//------------------------------------------------------------
// write the ending parts of the SOAP
//------------------------------------------------------------
SOAP = SOAP
//Requester
//+HDiv
+' </pcaRequestMain>' +crlf
+' </body>' +crlf
+' </uniEnvelope>' +crlf
+' </vrt:vrtvWrpPCA>' +crlf
+' </soapenv:Body>' +crlf
+' </soapenv:Envelope>' +crlf;
//-===========================================================
// Send request to server, and get response
//-===========================================================
http_debug(*ON);
soapfile = http_tempfile();
http_proxy_setauth( HTTP_AUTH_BASIC
: 'soauser'
: 'soapassword' );
rc = http_url_post(
'http://uwdatlesb01.srv.unisourcelink.net:2500/ws/+
VrtvPCA.SOA:vrtvPriceCostAvailability/VrtvPCA_SOA_vrtv+
PriceCostAvailability_Port'
//'http://uwdatlesb01.srv.unisourcelink.net:5573/+
// invoke/VrtvPCA.SOA.PCA/+
// vrtvPriceCostAvailability?'
: %addr(SOAP) + 2
: %len(SOAP)
: soapfile
: HTTP_TIMEOUT
: HTTP_USERAGENT
: 'text/xml'
:'http://uwdatlesb01.srv.unisourcelink.net:2500/ws/+
VrtvPCA.SOA:vrtvPriceCostAvailability/VrtvPCA_SOA_vrtv+
PriceCostAvailability_Port');
//:'http://uwdatlesb01.srv.unisourcelink.net:5573/+
// invoke/VrtvPCA.SOA.PCA/+
// vrtvPriceCostAvailability?');
//-===========================================================
// Check for Errors - if none, then PARSE the Inbound XML
// The response from the server will be in
// the IFS in a file with a unique name.
// that IFS filename is in the "tempfile"
// variable at this point.
//-===========================================================
if (rc <> 1);
callp http_error(err);
if err <> HTTP_NDAUTH;
http_crash();
endif;
rc = http_getauth(basic: digest: realm);
userid = 'soauser';
pass = 'soapassword';
if Digest;
http_setauth(HTTP_AUTH_MD5_DIGEST: userid:pass);
else;
http_setauth(HTTP_AUTH_BASIC:userid:pass);
endif;
rc = http_url_post(
'http://uwdatlesb01.srv.unisourcelink.net:2500/ws/+
VrtvPCA.SOA:vrtvPriceCostAvailability/VrtvPCA_SOA_vrtv+
PriceCostAvailability_Port'
//'http://uwdatlesb01.srv.unisourcelink.net:5573/+
// invoke/VrtvPCA.SOA.PCA/+
//vrtvPriceCostAvailability?'
: %addr(SOAP) + 2
: %len(SOAP)
: soapfile
: HTTP_TIMEOUT
: HTTP_USERAGENT
: 'text/xml'
:'http://uwdatlesb01.srv.unisourcelink.net:2500/ws/+
VrtvPCA.SOA:vrtvPriceCostAvailability/VrtvPCA_SOA_vrtv+
PriceCostAvailability_Port');
//:'http://uwdatlesb01.srv.unisourcelink.net:5573/+
//invoke/VrtvPCA.SOA.PCA/+
//vrtvPriceCostAvailability?');
endif;
if (rc <> 1);
http_crash();
endif;
embfile = http_tempfile();
if (http_parse_xml_stmf( soapfile
: HTTP_XML_CALC
: *null
: %paddr(SaveEmbed)
: %addr(embfile) ) < 0);
callp close(fd);
unlink(soapfile);
unlink(embfile);
http_crash();
Else;
//SaveEmbed(embfile:depth:name:path:value:attrs);
x=0;
Embedded(rtnlist:depth:name:path:value:attrs:x);
Exsr Cnvitems;
endif;
*inlr = *on;
return;
//-========================================================== =
// If no errors, then convert the item into MAX UOM/QTY
//-===========================================================
Begsr CnvITems;
x=1;
Dow X <= PCACount;
CNVITEM (PCAOUT(x));
x = x+1;
Enddo;
Endsr;
/end-free
P SaveEmbed B
D SaveEmbed PI
D embfile 50a varying
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 32767A varying const
D attrs * dim(32767)
D const options(*varsize)
D writeConst PR 10I 0 ExtProc('write')
D fildes 10i 0 value
D buf 65535A const options(*varsize)
D bytes 10U 0 value
D xmlhdr s 80a varying
D fd s 10i 0
/free
if (name <> 'PriceCostandAvailability');
return;
endif;
// ------------------------------------------
// create new stream file in IFS
// tag it with CCSID 1208 (UTF-8)
// ------------------------------------------
unlink(embfile);
fd = open(embfile: O_CREAT+O_CCSID+O_WRONLY
: S_IRUSR + S_IWUSR: 819);
callp close(fd);
// ------------------------------------------
// Open stream file for appending data
// and write embedded XML document to it
// ------------------------------------------
fd = open(embfile: O_WRONLY+O_TEXTDATA);
xmlhdr= '<?xml version="1.0" encoding="iso-8859-1"?>' + x'0d25';
writeConst(fd: xmlhdr: %len(xmlhdr));
writeConst(fd: value: %len(value));
callp close(fd);
/end-free
P E
P embedded B
D embedded PI
D PCAOUTDB likeds(PCAOUT) dim(200)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 32767A varying const
D attrs * dim(32767)
D const options(*varsize)
D X 10I 0 value
ss.999999
d DSRsitmAvl E DS extname(ITMAVAIL)
d prefix(O_)
d qualified
d dim(200)
/free
select;
//Availability List
when name = 'ItemId';
x=x+1;
o_ItemID(x) = %trimr(value);
when name = 'Description';
O_Desc(x) = %trimr(value);
when name = 'DivisionID';
O_DivID(x) = %trimr(value);
when name = 'SystemID';
O_sysId(x)= %trimr(value);
when name = 'StoreID';
O_Store(x) = %trimr(value);
when name = 'StoreName';
O_Strnme(x) = %trimr(value);
when name = 'Increment';
O_incrm(x)=%dec(value:10:0);
when name = 'MinimumPurchase';
O_MNpur(x)=%dec(value:10:0);
when name = 'PriceType';
O_prtyp(x) = %trimr(value);
when name = 'QuantityBackordered';
O_qtybo(x) =%dec(value:10:0);
when name = 'QuantityOnhand';
O_qtyoh(x) =%dec(value:10:0);
when name = 'QuantityOnOrder';
O_qtyoo(x) =%dec(value:10:0);
when name = 'QuantityReserved';
O_qtyrs(x) =%dec(value:10:0);
when name = 'StockingUOM';
O_Stuom(x) = %trimr(value);
when name = 'HomeUnits';
O_hunit(x)=%dec(value:10:0);
when name = 'TransferUnits';
O_Xunit(x)=%dec(value:10:0);
when name = 'TransferCutoffTime';
O_xcotm(x)=%dec(value:10:0);
when name = 'TransferDays';
O_xfday(x)=%dec(value:10:0);
when name = 'TransferFlag';
O_XFFLG(x) = %trimr(value);
when name = 'StatusMessage';
O_stmsg(x) = %trimr(value);
when name = 'ExtendedCost';
O_excst(x)=%dec(value:13:5);
when name = 'ExtendedFinancialCost';
O_exfcst(x)=%dec(value:13:5);
when name = 'Status';
O_Sts1(x) = %trimr(value);
when name = 'CertType';
O_Certyp(x) = %trimr(value);
endsl;
/end-free
P E
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------