[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Antwort: Re: Embedded XML



Thomas,

I made the changes in my code and it works ...
(I write the data to an ifs file)

Thanks a lot

thomas.raddatz@xxxxxx a écrit :
Franck,

here is a modified version of EXAMPLE15 that uses http_XmlReturnPtr().
Especially look at the use of "dsValue_t" and the modified procedure
interface of Incoming(). Also notice that I use memcpy() to access the
data. I do that in order be able to handle data larger that 64k. Instead of
using memcpy() to copy the data into a variable you may write the data to a
file.

Thomas.


     H DFTACTGRP(*NO) BNDDIR('HTTPAPI': 'QC2LE')
RADDAT

     FQSYSPRT   O    F  132        PRINTER OFLIND(*INOF)

 CPY  /copy qrpglesrc,httpapi_h
 CPY  /copy qrpglesrc,ifsio_h
RADDAT
      *  memcpy -- Copy Bytes
RADDAT
     D memcpy          PR              *          extproc('memcpy')
RADDAT
     D  i_pDest                        *   value
RADDAT
     D  i_pSrc                         *   value
RADDAT
     D  i_count                      10U 0 value
RADDAT
RADDAT
     D dsValue_t       ds                  qualified   based(pDummy)
RADDAT
     D  pData                          *
RADDAT
     D  length                       10I 0
RADDAT

     D Incoming        PR
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
    R ** value                    65535A   varying const
RADDAT
     D   dsValue                           likeds(dsValue_t)
RADDAT
     D   Attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D num             s             10I 0
     D item            ds                  occurs(10)   inz
RADDAT
     D   title                      512A   varying
     D   artlink                    512A   varying

     D msg             s             50A
     D rc              s             10I 0
     D url             s            100A   varying
     D PrintLine       s            132A
     D x               s             10I 0
     D filename        s             45A   varying

      /free

        *inlr = *on;
//RADDAT
        http_XmlReturnPtr(*ON);
//RADDAT

        // ****************************************************
        //  Download the latest news headlines from the
        //  System iNetwork to a temporary file in the IFS
        // ****************************************************
        url = 'http://feeds.feedburner.com/Search400iSeriesNewsAndAdvice';
//RADDAT
        filename = http_tempfile() + '.xml';

        rc = http_url_get( url : filename );
 B01    if (rc <> 1);
           PrintLine = http_error();
           except;
           unlink(filename);
           return;
 E01    endif;

        // ****************************************************
        //   parse the XML from the temp file.
        // ****************************************************

 B01    if (http_parse_xml_stmf( filename
                               : HTTP_XML_CALC
                               : *null
                               : %paddr(Incoming)
                               : *null ) < 0 );
           PrintLine = http_error();
           except;
           unlink(filename);
           return;
 E01    endif;

        // ****************************************************
        //  Print the news headlines & links to the full
        //   articles
        //
        //  Note:  If you wanted to, you could retrieve the
        //         articles themselves by calling http_url_get
        //         for each link.
        // ****************************************************

 B01    for x = 1 to num;
           %occur(item) = x;
           PrintLine = title;
           except;
           PrintLine = '  ' + artlink;
           except;
           PrintLine = '';
           except;
 E01    endfor;

        unlink(filename);
        return;

      /end-free

     OQSYSPRT   E
     O                       PrintLine          132


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  This is called for each XML element that's received in the
      *  document. The document that's received will look something
      *  like the following:
      *
      *     <rss version="2.0">
      *       <channel>
      *         <title>System iNetwork News Headlines</title>
      *         <link>http://www.systeminetwork.com</link>
      *         <description>System i Headlines</description>
      *         <language>en-US</language>
      *         <copyright>Copyright - Penton Media 2003</copyright>
      *         <item>
      *           <title>Title of first article</title>
      *           <link>link to first article</link>
      *         </item>
      *         <item>
      *           <title>Title of second article</title>
      *           <link>link to second article</link>
      *         </item>
      *       </channel>
      *     </rss>
      *
      *  The DEPTH parameter indicates the nesting depth of the
      *  element received.  In the above example, the "item" tag
      *  would be found at depth=3, since it's inside the "rss"
      *  and "channel" tags.
      *
      *  The NAME parameter is the name of the XML element that
      *  has been received.  It might be something like "channel"
      *  or "title" or "link".
      *
      *  Note that in the above example, there are two different
      *  depths that have "title" and "link".  They are featured
      *  inside the "channel" tag, and also inside the "item" tag.
      *  the "path" parameter will help us sort that out.
      *
      *  The PATH indicates the elements that the current element
      *  is found inside. So, the channel title is found when the
      *  path is "/rss/channel" and the name of the element is "title".
      *  the article titles, however, have a path of "/rss/channel/item"
      *  and a name of "title".
      *
      *  The VALUE parameter gives us the text that's inside that
      *  element.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P Incoming        B
     D Incoming        PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
    R ** value                    65535A   varying const
RADDAT
     D   dsValue                           likeds(dsValue_t)
RADDAT
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D count           s             10I 0
     D attrname        s            100A   varying
     D attrval         s            100A   varying
      /free

 B01     if (path = '/rss/channel/item');
//RADDAT

 B02        select;
            when name = 'title';
               num = num + 1;
               %occur(item) = num;
 B03           if (dsValue.length < 512);
//RADDAT
                  %len(title) = dsValue.length;
//RADDAT
 X03           else;
//RADDAT
                  %len(title) = 512;
//RADDAT
 E03           endif;
//RADDAT
               memcpy(%addr(title)+2: dsValue.pData: %len(title));
//RADDAT
               // title = value;
//RADDAT
            when name = 'link';
 B03           if (dsValue.length < 512);
//RADDAT
                  %len(artlink) = dsValue.length;
//RADDAT
 X03           else;
//RADDAT
                  %len(artlink) = 512;
//RADDAT
 E03           endif;
//RADDAT
               memcpy(%addr(artlink)+2: dsValue.pData: %len(artlink));
//RADDAT
               // artlink = value;
//RADDAT
 E02        endsl;

 E01     endif;

      /end-free
     P                 E





ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx schrieb am 04.11.2008 15:30:38:

Scott,

I'm trying  to use XmlReturnPtr().

I have some problems to define the data structure. ( found in this link
http://www.scottklement.com/archives/ftpapi/200709/msg00047.html)

Then, the 'value' parameter that's passed to your end element handler
will no longer be a VARYING string.  instead, it'll be a data structure
that consists of a pointer in the first 16 bytes, and a 4-byte binary
integer (10i 0 in RPG) that constains the length of the data at the
pointer.  Ths integer is in bytes 17-20 of the data structure.

Can you help me (or someone else ) ?

Thanks

Franck Peter a écrit :
Scott,

I use 1.23 HTTPAPI version.

Sometimes I can receive 64k bigger documents so I'm very interested by
the use of

HTTP_XmlReturnPtr().

Can you explain me a little or send me a source with
HTTP_XmlReturnPtr()?
Thanks


--
IMPORTANT NOTICE:
This email is confidential, may be legally privileged, and is for the
intended recipient only. Access, disclosure, copying, distribution, or
reliance on any of it by anyone else is prohibited and may be a criminal
offence. Please delete if obtained in error and email confirmation to the sender.
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------

.


begin:vcard
fn:Franck Peter
n:Peter;Franck
org:SDV LI;Informatique
email;internet:mrs.infosys@xxxxxxx
tel;work:04.42.02.44.66
tel;fax:04.42.89.42.89
version:2.1
end:vcard

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------