× 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.



It has been quite a few years since I wrote some XML processing routines and
I know I did not like how XML-INTO worked.
I used XML-SAX and ended up writing my own XML element processing handler
routine.

An MXL handler will process one XML element at a time. I used a huge
multi-dimensional data structure (I was dealing with 80 to 100 fields in
nested elements) and keep an index tracker to know how deep I had drilled
down into each section.

Here are a few snips to give you an idea what is involved.

//-- there be dragons here

XML-SAX %handler( XmlSaxHandler : Ref_Info )
%XML( qualFileName : xml_options );

*---------------------------------------------------------------------
*---------------------------------------------------------------------
P XmlSaxHandler B
D PI 10I 0
D Ref_Info LikeDS(Ref_Info_ds)
D iEvent 10I 0 Value
D iStringPtr * Value
D iStringLen 20I 0 Value
D iExceptionId 10I 0 Value

D wStringDta S 65535A Based(iStringPtr)
D iStringDta S 65535A Varying
D i S 10I 0
/free
monitor;
Ref_Info.Proc_Actn = $PROC_CONT;

if iStringLen > 0;
iStringDta = %subst( wStringDta : 1 : iStringLen );
else;
iStringDta = '';
endif;

Select;
When iEvent = *XML_START_DOCUMENT;
clear Element.Data;
lvlIdx = 0;
firstOrder = *on;


When iEvent = *XML_START_ELEMENT or iEvent = *XML_ATTR_NAME;
lvlIdx += 1;
if lvlIdx = 1;
lvlPath(lvlIdx) = iStringDta;
else;
lvlPath(lvlIdx) = lvlPath(lvlIdx-1) + '.' + iStringDta;
endif;
// clear data when start is found so xml_chars can concatenate
i = %lookup(lvlPath(lvlIdx):Element.Path);
if i > 0;
Element.Data(i) = '';
endif;


when iEvent = *XML_CHARS or iEvent = *XML_PREDEF_REF or
iEvent = *XML_ATTR_CHARS;
i = %lookup(lvlPath(lvlIdx):Element.Path);
if i > 0;
Element.Data(i) += iStringDta;
endif;


when iEvent = *XML_END_ELEMENT or iEvent = *XML_END_ATTR;
lvlIdx -= 1;

select;
when iStringDta = 'InvoiceDetail';
exsr ProcessDetail;

when iStringDta = 'InvoiceHeaderFields';
exsr ProcessHeader;

when iStringDta = 'Invoice';
exsr ProcessInvoice;

when iStringDta = 'InvoiceBridge';
// end of xml file
exsr WriteHeader;

endsl;
endsl;

on-error *FILE;
return -1;
on-error *ALL;
return -1;
endmon;

return 0;




-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Lim Hock-Chai
Sent: Tuesday, March 05, 2013 4:27 PM
To: 'rpg400-l@xxxxxxxxxxxx'
Subject: Re: XML-INTO - %XML option to treat null element as 0

Yes, those are the options I'm using. As far as I can tell, when XML-INTO
encountered a mapping error, it will abort the rest of mapping.

<darren@xxxxxxxxx> wrote in message
news:<mailman.17666.1362518053.10847.rpg400-l@xxxxxxxxxxxx>...
First thing to try would be to put an INZ on your data structure
definition. That will initialize the numeric to zero. What options
are you using? I use the following, and I don't ever expect a
numeric. I convert the character to numeric in a later operation when
required, although that doesn't mean what you're trying isn't possible:

+ 'allowmissing=yes '
+ 'allowextra=yes '
+ 'case=any');



From: "Hockchai Lim" <lim.hock-chai@xxxxxxxxxxxxxxx>
To: rpg400-l@xxxxxxxxxxxx,
Date: 03/05/2013 03:54 PM
Subject: XML-INTO - %XML option to treat null element as 0
Sent by: rpg400-l-bounces@xxxxxxxxxxxx



Is there a %XML option that I can use to make XML-INTO treats null
element that maps to a numeric field as 0?

For example:
The XML has:
<ESI_DATA_ENTRY>
<Data_Type/>
<Data_LEN/>
<DATA/>
</ESI_DATA_ENTRY>


My DS has:
D ESI_DATA_ENTRY
D ds
D data_type 24
D data_len 2S 0
D data 128


The XML-INTO error out when it encountered <Data_LEN/>. I think it is
because it is expecting a numeric value but it contains nothing.


--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.



--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



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.