|
From: larry_ducie@xxxxxxxxxxx
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: XML-SAX not quite right
Date: Tue, 11 Nov 2008 23:50:44 +0000
Hi Sharon,
This SAX parser works by reading through your xml document and firing a call to your handler procedure every time an event occurs.
You have code for some events, but you are missing a crucial one - *XML_CHARS.
Consider the following trivial example:
<?xml version="1.0" ?>
<root>
<SKU>PT0110</SKU>
</root>
you should get the following calls:
*XML_START_DOCUMENT
*XML_START_ELEMENT - value passed is 'root'
*XML_START_ELEMENT - value passed is 'SKU'
*XML_CHARS - value passed is 'PT0110'
*XML_END_ELEMENT - value passed is 'SKU'
*XML_ENDELEMENT - value passed is 'root'
*XML_END_DOCUMENT
You are not handling what happens when the *XML_CHARS event occurs.
Also, you will not know what element the *XML_CHARS relates to unless you hold a variable telling you what the last *XML_START_ELEMENT had as the value. I would suggest you define a static variable in your sub-proc and set it to the value of the element name during the *XML_START_ELEMENT event and clear it during the *XML_END_ELEMENT. This is not the best way to go for more complicated documents though.
If you are to do this in a robust manner you should have a static variable containing the full path to your current element and add elements to the path in *XML_START_ELEMENT and remove them in *XML_END_ELEMENT.
For the above list of events you would set your path to look like this:
*XML_START_DOCUMENT - path = '/'
*XML_START_ELEMENT - path = 'root'
*XML_START_ELEMENT - path = '/root/SKU'
*XML_CHARS - path is unchanged but you get the value of SKU here as you are in /root/SKU
*XML_END_ELEMENT - path = '/root'
*XML_END_ELEMENT - path = '/'
*XML_END_DOCUMENT path = ''
Thus you would store the value of the SKU when a *XML_CHARS event is fired and your path = '/root/SKU'.
Hope this makes sense.
Cheers
Larry Ducie
_________________________________________________________________
It's simple! Sell your car for just $40 at CarPoint.com.au
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641&_t=762955845&_r=tig_OCT07&_m=EXT
--
This is the RPG programming on the AS400 / 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 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.