[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xml-sax issue
Thanks Alan,
I'll make use of that.
> This is a little program I use to check what is coming on to SAX
> Procedure. Just step through it in debug and you can see what is coming
> in.
> Â Â Â Â Â Â Â ctl-opt Option(*Srcstmt:*NoUnref:*Nodebugio);
> Â Â Â Â Â Â ctl-opt Main(TestExtract);
> Â Â Â Â Â Â dcl-pr TestExtract ExtPgm('TESTEXTRA3') end-pr;
> Â Â Â Â Â Â dcl-ds TD_CommunicationArea Qualified Template;
> Â Â Â Â Â Â Â Â TagNameSeen Ind Inz('0');
> Â Â Â Â Â Â Â Â FileName VarChar(40);
> Â Â Â Â Â Â Â Â FileHandle Int(10);
> Â Â Â Â Â Â end-ds;
> Â Â Â Â Â * - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - -
> Â Â Â Â Â * TestExtract
> Â Â Â Â Â *Â Â This function tests XML SAX processing.
>      * Input      - None.
>      * Out        - None.
>      * Returns    - None.
> Â Â Â Â Â * - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - -
> Â Â Â Â Â Â dcl-proc TestExtract;
> Â Â Â Â Â Â Â Â dcl-pi *N end-pi;
> Â Â Â Â Â Â Â Â dcl-ds CommunicationArea LikeDs(TD_CommunicationArea)
> Inz(*LikeDs);
> Â Â Â Â Â Â Â Â dcl-s OriginalFile VarChar(40);
> Â Â Â Â Â Â Â Â dcl-s Options VarChar(126);
> Â Â Â Â Â Â Â Â OriginalFile = '/tmp/response01';
> Â Â Â Â Â Â Â Â Options = 'doc=file';
> Â Â Â Â Â Â Â Â XML-Sax %Handler(CallbackHandler:
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CommunicationArea)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â %Xml(OriginalFile:
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Options);
> Â Â Â Â Â Â Â Â Return;
> Â Â Â Â Â Â end-proc;
> Â Â Â Â Â * - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - -
> Â Â Â Â Â * CallbackHandler
> Â Â Â Â Â *Â Â This function is called by XML-SAX and receives chucks
> of data and tags
>      * Input      - Communications area. Pass data back
> and forth.
> Â Â Â Â Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Event number
> Â Â Â Â Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Pointer to data. This allows
> any amount of data
> Â Â Â Â Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Length of data.
> Â Â Â Â Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Kind of exception seen.
>      * Out        - None.
>      * Returns    - Whether to shut down the process.
> Â Â Â Â Â * - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - -
> Â Â Â Â Â Â dcl-proc CallbackHandler;
> Â Â Â Â Â Â Â Â dcl-pi *N Int(10);
> Â Â Â Â Â Â Â Â Â Â InOutCommunicationArea
> LikeDs(TD_CommunicationArea);
> Â Â Â Â Â Â Â Â Â Â InEvent Int(10) Value;
> Â Â Â Â Â Â Â Â Â Â InPointerToData Pointer Value;
> Â Â Â Â Â Â Â Â Â Â InDataLength Int(20) Value;
> Â Â Â Â Â Â Â Â Â Â InExceptionId Int(10) Value;
> Â Â Â Â Â Â Â Â end-pi;
> Â Â Â Â Â Â Â Â dcl-s Data Char(65535) Based(InPointerToData);
> Â Â Â Â Â Â Â Â dcl-s DataActual VarChar(1024);
> Â Â Â Â Â Â Â Â dcl-s Count Int(10);
> Â Â Â Â Â Â Â Â // All the events that can be monitored. Normally you
> would
> Â Â Â Â Â Â Â Â //Â Â use *XML_START_ELEMENT, *XML_CHARS and
> *XML_END_ELEMENT.
> Â Â Â Â Â Â Â Â Select;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_START_ELEMENT;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_CHARS;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_END_ELEMENT;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_START_DOCUMENT;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_VERSION_INFO;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_ENCODING_DECL;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_STANDALONE_DECL;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_DOCTYPE_DECL;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_PREDEF_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_UCS2_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_UNKNOWN_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_ATTR_NAME;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_ATTR_CHARS;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_ATTR_PREDEF_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_ATTR_UCS2_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_UNKNOWN_ATTR_REF;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_END_ATTR;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_PI_TARGET;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_PI_DATA;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_START_CDATA;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_END_CDATA;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_COMMENT;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_EXCEPTION;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â Â Â When InEvent = *XML_END_DOCUMENT;
> Â Â Â Â Â Â Â Â Â Â Â Â Count += 1;
> Â Â Â Â Â Â Â Â EndSl;
> Â Â Â Â Â Â Â Â If InDataLength > 0;
> Â Â Â Â Â Â Â Â Â Â DataActual = %Subst(Data:1:InDataLength);
> Â Â Â Â Â Â Â Â EndIf;
> Â Â Â Â Â Â Â Â Return 0;
> Â Â Â Â Â Â end-proc;
> On Sat, Sep 5, 2015 at 12:59 AM, Scott Klement <[1]sk@xxxxxxxxxxxxxxxx>
> wrote:
>
> Dutch,
> You are doing this:
> xml = %trim(%subSt(GetResponse:3:5000));
> Can you explain why you are doing that %subst? Wouldn't that cause
> the '<M' at the start of the XML document to be chopped off, making
> this an invalid document?
> The %trim() is not necessary, but shouldn't hurt anything.
> Can you explain why you want to use XML-SAX here instead of XML-INTO
> or the XML parser included with HTTPAPI? (Which is a wrapper
> around Expat)
> On 9/4/2015 4:34 PM, RPG List wrote:
>
> Scott,
> I'm not sure we don't have another problem. Here's why when I step
> through the xmlhandler, I get the start_document on the first read,
> and
> then I get end_document on the second read. That's it. Its
> almost as
> though its never seeing the data further. I ran a test using the
> following:
> XML = '<xmlTest>+
> Â Â Â Â Â Â Â Â <name type="author">AS400 Sample Code/name>+
> Â Â Â Â Â Â Â Â </xmlTest>';
> that worked.
> Here is what the xml document looks like coming in:
> '<MMMProcess><Results><Claim>8104550</Claim><Amount>1995.83</'
> 'Amount><Code>7320</Code><Xrg>53</Xrg><MEANLOS2>2</MEAN'
> 'LOS2><Error_Code>0</Error_Code></Results></MMMProcess>'
> I just can't find what's wrong with the xml..
>
> Dutch,
> The XML processing instructions ("header" as you call it) are
> optional.
> They are not required.
> The problem is what I said in my first reply to you. Please read
> the
> article I linked to so you can learn how XML-SAX works.
> -SK
> On 9/4/2015 3:18 PM, RPG List wrote:
>
> one additional issue I saw this morning Scott and maybe this is the
> problem, the incoming XML does not have what I would call a standard
> header:
> IE: it does not have a version or description that I see in most xml
> documents, maybe that's needed or maybe not?
>
> Dutch,
> This looks an awful lot like a program that I wrote a long time ago
> to
> print the XML events. I would not recommend using this to actually
> parse a document -- to parse with XML-SAX you're going to need to
> create
> a stack of XML elements (implemented in RPG as an array, most
> likely)
> and keep track of the current XML element you're working on, etc.
> There
> was another program included in that same article called "CustXml"
> that
> demonstrates this -- that program would be a better starting point.
> [2]http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-opcod
> e
> (use the "print" option to format the code better, Penton media has
> screwed up the code figures in their article archive)
> Based on what you've shown us, the only thing you'd get in your
> string
> is the name of the XML tag you're parsing. (Since that's what's
> pointed
> to by "string" during the XML_START_ELEMENT event.)
> You say you're getting nothing at all...? Since you're getting it
> from
> the 'value' field, you'd need to show us the definition and/or code
> that
> populates 'value' for us to see how that works. Funny that you
> omitted
> that part of the code considering that your question is about it?
> Also, is this part of a program that uses HTTPAPI or FTPAPI? If
> so, I
> guess we can discuss it here...  if not, however, this really
> doesn't
> belong on this mailing list.
> -SK
> On 9/3/2015 9:17 PM, RPG List wrote:
>
> I am attempting to parse out the data I'm getting from a web service
> and
> I'm having a little trouble.
> I'm using the following as my to the handler:
> Â Â Â xml = %trim(%subSt(GetResponse:3:5000));
> Â Â Â xml-sax %handler(xmlHandler: ignoreMe)
> Â Â Â Â Â %XML(xml: 'doc=string');
> GetResponse has the full xml string I'm expecting.
> my xmlhandler is defined as follows:
> P xmlHandler   b
> D         pi      10i 0
> D ignore             1a
> D event             10i 0 value
> D  string            *  value
> D  stringLen          20i 0 value
> D  exceptionId         10i 0 value
> I then have the following code in the procedure:
> OutputXML.name = XML_Event_Name(event);
> OutputXML.data = *blanks;
> select;
> when string=*null or stringlen<1;
> Â Â Â // no string given...
> when stringlen>%size(value);
> Â Â Â OutputXML.data = '** string length invalid';
> other;
> Â Â Â OutputXML.data = %subst(value:1:stringlen);
> endsl;
> // Change Current XML group if applicable
> Select;
> Â Â Â When OutputXML.name = 'XML_START_ELEMENT';
> The problem is outputXML.data never has a value that I can see. Am
> I
> doing something wrong or am I missing a step?
>
> --------------------------------------------------------------------
> ---
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> [3]http://www.scottklement.com/mailman/listinfo/ftpapi
> --------------------------------------------------------------------
> ---
>
> References
>
> 1. mailto:sk@xxxxxxxxxxxxxxxx
> 2. http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-opcode
> 3. http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------