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

RE: Example15 - Looking for help accessing the data from attrs



      /include httpapi_h

     D Incoming        PR
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

             rc = http_url_post_xml(
                  'http://yourwebservice'
                  : %addr(SOAP) + 2
                  : %len(SOAP)
                  : *NULL
                  : %paddr(Incoming)
                  : %addr(ATAXML)
                  : timeout
                  : HTTP_USERAGENT
                  : 'text/xml'
                  : PartRetrieve.SoapAction);


     P Incoming        B
     D Incoming        PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D atof            PR             8F   extproc('atof')
     D   string                        *   value options(*string)


     d count           s             10i 0
     D attrname        s           1024A   varying
     D attrval         s          65535A   varying
     D testd           s             30A

      /free

       if (%trim(name) = 'Whateverelementname');

         count = 1;
         dow http_nextXmlAttr(attrs: count: attrname: attrval);
           if (%trim(attrname) = 'Whateverattributename');
               do something with your attribute  
           endif;
         enddo;

       ENDIF;

      /end-free
     P                 E

Or see example11.

     H DFTACTGRP(*NO) BNDDIR('HTTPAPI')

     FQSYSPRT   O    F  132        PRINTER OFLIND(*INOF)

      /copy qrpglesrc,httpapi_h
      /copy qrpglesrc,ifsio_h

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

     D num             s             10I 0
     D item            ds                  occurs(10)
     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;
        http_debug(*ON);

        // ****************************************************
        //  Download the latest news headlines from CNN
        //  to a temporary file in the IFS
        // ****************************************************
        url = 'http://rss.cnn.com/rss/cnn_topstories.rss';
        filename = http_tempfile() + '.xml';

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

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

        if (http_parse_xml_stmf( filename
                               : HTTP_XML_CALC
                               : *null
                               : %paddr(Incoming)
                               : *null ) < 0 );
           PrintLine = http_error();
           except;
           unlink(filename);
           return;
        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.
        // ****************************************************

        if num > %elem(item);
           num = %elem(item);
        endif;

        for x = 1 to num;
           %occur(item) = x;
           PrintLine = title;
           except;
           PrintLine = '  ' + artlink;
           except;
           PrintLine = '';
           except;
        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>Title of Newsfeed channel</title>
      *         <link>http://www.blahblahblah.com</link>
      *         <description>Whatever Headlines</description>
      *         <language>en-US</language>
      *         <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
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     D count           s             10I 0
     D attrname        s           1024A   varying
     D attrval         s          65535A   varying
      /free
         if (num > %elem(item));
             return;
         endif;

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

            select;
            when name = 'title';
               num = num + 1;
               if (num <= %elem(item));
                  %occur(item) = num;
                  title = value;
               endif;
            when name = 'link';
               artlink = value;
            endsl;

         endif;


         // sometimes an element will have attributes.  In the example
         // XML shown above, the only attribute is the VERSION attrib
         // of the RSS tag.
         //
         // The following searches through the attribute list of the
         // rss tag to extract the version number.

         if (name = 'rss');

            count = 1;
            dow http_nextXmlAttr(attrs: count: attrname: attrval);
               if (attrname = 'version');
                  PrintLine = 'RSS version ' + attrval;
                  except;
               endif;
            enddo;

         endif;

      /end-free
     P                 E

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Don Brown
Sent: 10 January 2013 09:13 AM
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: Example15 - Looking for help accessing the data from attrs

Hello all,

My source for example15 only has the following;

*************** Beginning of data *****************************
 **  This should be another POX example.  Maybe one where 
 **  it demonstates calling a local RPG program? 
c                   eval      *inlr = *on 


Searching the history archives I found a reference to this example for 
retrieving the data from the address in array attrs.



I am receiving back the following response from a web service call and 
would like to know how to retrieve the data at the address in the attrs 
array.

In the procedure passed for the end of element processing i am receiving 
the xml element name but there is nothing in the value.  I believe I need 
to retrieve the value from the address of each element in the attrs array 
but can not find an example of how to do this.

Would appreciate any help.

Thank you and regards

SetError() #13: HTTP/1.1 200 OK
recvresp(): end with 200
recvdoc parms: identity 720
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsd="
http://www.w3.org/2001/XMLSchema"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"; xmlns:SOAP-ENC="
http://schemas.xmlsoap.org/soap/encoding/
"><SOAP-ENV:Body><sendMessagesResponse xmlns="http://xml.m4u.com.au/2009";>
  <result sent="0" scheduled="0" failed="1">
    <accountDetails type="daily" creditLimit="20" creditRemaining="20"/>
    <errors>
      <error code="other" sequenceNumber="0">
        <recipients>
          <recipient uid="0">61408751644</recipient>
        </recipients>
      </error>
    </errors>
  </result>
</sendMessagesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>


Don Brown

MSD Information Technology 

Suite 5/29 McDougall Street Milton Q  4064
(  07 3368 7888
+ PO Box 1629 MILTON  Q  4064
Ê  07 3368 7877
*  Don.Brown@xxxxxxxxxx  
È 0408 751 644
þ  www.msd.net.au  www.architect4web.com.au 
 

 


I am a proud supporter of THE REFERRAL NETWORK and recommend the services 
of the other member businesses. For more information please checkout the 
website www.refnet.net.au

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