Hello all, I am trying to learn the new opcodes XML-INTO and XML-SAX.
The first one was not that bad, but I have been trying to get the XML-SAX to work based on the Redbook examples and I know I am close but am missing something.
I doctored an XML document to have more than one set of elements so I could test this, we hope to get multiple element documents from this new vendor.
When I get this to run I have either blanks in the data area fields or all *'s. Also it looks like it loops through the procedure with no end, not sure about that.
ANY help would be greatly appreciated.
Sharon
Here is my code:
H debug(*XMLSAX)
Fqsysprt O F 132 printer
D*
D Quantity S 16A
D SKU S 16A VARYING
D string S 16A VARYING
D SRSReturn DS QUALIFIED
D DataArea LIKEDS(DataArea)
D* DIM(999)
*
DDataArea DS QUALIFIED
D pValue *
D storeNumber 16A
D transDate 16A
D localTrans 16A
D centTrans 16A
D Status 16A
D AssociateID 16A
D refundPolicy 16A
D TotalCredit 16A
D ConversCredit 16A
D Customer LikeDS(Customer)
D Item LikeDS(Item)
D ReturnPaymInfo LikeDS(ReturnPayment)
D ReturnMsg 16A
D*
DCustomer DS Qualified
D CustomerID 16A
D FirstName 16A
D LastName 16A
DItem DS Qualified
D ItemStatus 16A
D SKU 16A
D Quantity 16A
D CreditAmount 16A
D TaxAmount 16A
D AdjustmentCred 16A
D ItemTotalCred 16A
D centordid 16A
D origordid 16A
DReturnpayment DS QUALIFIED
D ReturnMethod 16A
D ReturnAmount 16A
D ProtocolData 16A
D*
D qsysprtDs DS 132
D value_t S 50A VARYING
D* alwExtraAttr 1N
D*
Dmydataarea DS likeds(DataArea)
DsaxHandler PR 10I 0
D info likeds(DataArea)
D event 10I 0 value
D string * value
D stringlen 20I 0 value
D exceptionId 10I 0 value
D psds DS
D xmlRc 10I 0 OVERLAY(psds:368)
/free
monitor;
// myDataArea.alwExtraAttr = *OFF;
XML-SAX %HANDLER(SaxHandler : DataArea)
%XML('/home/sstrippoli/xml/srsoutput8.xml' : 'doc=file');
// qsysprtDs = 'There are '
// + myDataArea.Quantity
// + 'of sku '
// + myDataArea.SKU
// + ' in store '
// + myDataArea.storeNumber;
on-error 00351;
qsysprtDs = 'XML parser error: rc='
+ %CHAR(xmlRc)
+ '.';
endmon;
write qsysprt qsysprtDs;
*inlr = '1';
/end-free
P SaxHandler B
D PI 10I 0
D info LIKEDS(dataarea)
D event 10I 0 VALUE
D stringPtr * VALUE
D stringLen 20I 0 VALUE
D exceptionId 10I 0 VALUE
D value S LIKE(value_t)
D* BASED(info.pValue)
D chars S 65535A BASED(stringPtr)
D ucs2 S 16383C BASED(stringPtr)
D ucs2Len S 10I 0
/free
select;
// start parsing
when event = *XML_START_DOCUMENT;
// clear info;
when event = *XML_START_ELEMENT;
if %subst(chars : 1 : stringLen) = 'SKU';
// info.handlingAttrs = *ON;
info.storeNumber = '';
// info.SKU = '';
// info.Quantity = '';
endif;
if string = 'storeNumber'; (just wanted to see if I had a value at this point)
endif;
// display information about the sku
when event = *XML_END_ELEMENT;
if %subst(chars : 1 : stringLen) = 'SKU';
// info.handlingAttrs = *OFF;
qsysprtDs = 'SKU '
+ info.sku
+ ' is from store'
+ info.storeNumber;
//
write qsysprt qsysprtDs;
endif;
// handle an exception
when event = *XML_EXCEPTION;
qsysprtDs = 'Exception '
+ %char(exceptionId)
+ ' occurred.';
write qsysprt qsysprtDs;
return exceptionId;
other;
endsl;
return 0;
/end-free
P SaxHandler E
xml document:
<?xml version="1.0" encoding="IBM037"?>
<!DOCTYPE SRSReturn SYSTEM "/home/sstrippoli/SRSReturns.dtd">
<SRSReturn version="1.0">
<DataArea>
<storeNumber>7</storeNumber>
<transDate>20081028</transDate>
<localTransactionNumber>52221433</localTransactionNumber>
<centralTransactionNumber>123457</centralTransactionNumber>
<Status>I</Status>
<AssociateID>2257752</AssociateID>
<refundPolicy>D</refundPolicy>
<TotalCredit></TotalCredit>
<ConversionCredit>44.50</ConversionCredit>
<Customer>
<CustomerID>1111333444</CustomerID>
<FirstName>Mickey</FirstName>
<LastName>Mouse</LastName>
</Customer>
<Item>
<ItemStatus>R</ItemStatus>
<SKU>647182</SKU>
<Quantity>1</Quantity>
<CreditAmount>44.50</CreditAmount>
<TaxAmount>3.95</TaxAmount>
<AdjustmentCredit>0</AdjustmentCredit>
<ItemTotalCredit>44.50</ItemTotalCredit>
<CentralOrderItemId>647182888</CentralOrderItemId>
<OriginalOrderItemId>647182888</OriginalOrderItemId>
</Item>
<ReturnPaymentInfo>
<ReturnMethod>I</ReturnMethod>
<ReturnAmount>44.50</ReturnAmount>
<ProtocolData>458111446</ProtocolData>
</ReturnPaymentInfo>
<ReturnMsg>error</ReturnMsg>
</DataArea>
<DataArea>
<storeNumber>7</storeNumber>
<transDate>20081028</transDate>
<localTransactionNumber>52221433</localTransactionNumber>
<centralTransactionNumber>123457</centralTransactionNumber>
<Status>I</Status>
<AssociateID>2257752</AssociateID>
<refundPolicy>D</refundPolicy>
<TotalCredit></TotalCredit>
<ConversionCredit>44.50</ConversionCredit>
<Customer>
<CustomerID>1111333444</CustomerID>
<FirstName>Tom</FirstName>
<LastName>Smith</LastName>
</Customer>
<Item>
<ItemStatus>R</ItemStatus>
<SKU>647182</SKU>
<Quantity>1</Quantity>
<CreditAmount>44.50</CreditAmount>
<TaxAmount>3.95</TaxAmount>
<AdjustmentCredit>0</AdjustmentCredit>
<ItemTotalCredit>44.50</ItemTotalCredit>
<CentralOrderItemId>647182888</CentralOrderItemId>
<OriginalOrderItemId>647182888</OriginalOrderItemId>
</Item>
<ReturnPaymentInfo>
<ReturnMethod>I</ReturnMethod>
<ReturnAmount>44.50</ReturnAmount>
<ProtocolData>458111446</ProtocolData>
</ReturnPaymentInfo>
<ReturnMsg>error</ReturnMsg>
</DataArea>
</SRSReturn>
Here is the DTD for the document:
<!ELEMENT SRSReturn (DataArea)>
<!ATTLIST SRSReturn version CDATA #FIXED "1.0">
<!ELEMENT DataArea
(storeNumber?,transDate?,localTransactionNumber?,centralTransactionNumber?,Status?,AssociateID?,refundPolicy?,TotalCredit?,ConversionCredit?,Customer?,Item*,ReturnPaymentInfo*,
ReturnMsg?) >
<!ELEMENT storeNumber (#PCDATA)>
<!ELEMENT transDate (#PCDATA)>
<!ELEMENT localTransactionNumber (#PCDATA)>
<!ELEMENT centralTransactionNumber (#PCDATA)>
<!ELEMENT Status (#PCDATA)>
<!ELEMENT AssociateID (#PCDATA)>
<!ELEMENT refundPolicy (#PCDATA)>
<!ELEMENT TotalCredit (#PCDATA)>
<!ELEMENT ConversionCredit (#PCDATA)>
<!ELEMENT Customer (CustomerID?,FirstName?,LastName?) >
<!ELEMENT CustomerID (#PCDATA)>
<!ELEMENT FirstName (#PCDATA)>
<!ELEMENT LastName (#PCDATA)>
<!ELEMENT Item
(ItemStatus?,SKU?,Quantity?,CreditAmount?,TaxAmount?,AdjustmentCredit?,ItemTotalCredit?,CentralOrderItemId?,OriginalOrderItemId)
<!ELEMENT ItemStatus (#PCDATA)>
<!ELEMENT SKU (#PCDATA)>
<!ELEMENT Quantity (#PCDATA)>
<!ELEMENT CreditAmount (#PCDATA)>
<!ELEMENT TaxAmount (#PCDATA)>
<!ELEMENT AdjustmentCredit (#PCDATA)>
<!ELEMENT ItemTotalCredit (#PCDATA)>
<!ELEMENT CentralOrderItemId (#PCDATA)>
<!ELEMENT OriginalOrderItemId (#PCDATA)>
<!ELEMENT ReturnPaymentInfo (ReturnMethod?,ReturnAmount?,ProtocolData?) >
<!ELEMENT ReturnMethod (#PCDATA)>
<!ELEMENT ReturnAmount (#PCDATA)>
<!ELEMENT ProtocolData (#PCDATA)>
<!ELEMENT ReturnMsg (#PCDATA)>
_________________________________________________________________
See how Windows® connects the people, information, and fun that are part of your life
http://clk.atdmt.com/MRT/go/119463819/direct/01/
As an Amazon Associate we earn from qualifying purchases.