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

Re: &lt; and &gt; in stead of < and >



   Hi Scott.
   Thanks a million for your swift and precise help.
   Your advice combined with the example in your answer to Bruce  (Jan
   07. 2009.)
   in a quite different case (Where the solution is not so different) it
   was easy even to a novice like me.
   [1]http://www.scottklement.com/archives/ftpapi/200901/msg00046.html
   In case it is of interest for others - when receiving an XML embedded
   (as ONE loooong  string value)  in an other XML....
   Here is the complete program listing needed for the 2 step process..
   First         - getting (via a Soap request)  the complete xml, and
   extracting the INNER XML and storing that in an IFS-file
           (in this process the &lt; and &gt; in the string  are
   replaced by  < and >  )
   Second- parsing the resulting IFS-file to do the normal data
   extraction...
   H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')





    /copy httpapi_h

    /copy ifsio_h



   D Element_Val_t   ds                  qualified

   D                                     based(Template)

   D    buf                          *

   D    len                        10i 0



   D GetInnerDoc     PR

   D   filename                    50a   varying

   D   depth                       10I 0 value

   D   name                      1024A   varying const

   D   path                     24576A   varying const

   D   value                             likeds(Element_Val_t)

   D   Attrs                         *   dim(32767)

   D                                     const options(*varsize)



   D Incoming        PR

   D   rate                         8F

   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 SOAP            s          32767A   varying
   D rc              s             10I 0
   D rate            s              8F
   D Result          s             12P 2
   D Filename        s             50a   varying

    /free
     // Note:  http_debug(*ON/*OFF) can be used to turn debugging
     //        on and off.  When debugging is turned on, diagnostic
     //        info is written to an IFS file named
     //        /tmp/httpapi_debug.txt

     http_debug(*ON);
     http_xmlReturnPtr(*ON);
     filename = http_tempfile() + '.xml';

     // Note:  http_XmlStripCRLF(*ON/*OFF) controls whether or not
     //        the XML parser removes CR and LF characters from the
     //        Xml data that's passed to your 'Incoming' procedure.

     http_XmlStripCRLF(*ON);

     SOAP =
      '<?xml version="1.0" encoding="utf-8"?>'
     +'<SOAP:Envelope'
     +'    xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/";'
     +'    xmlns:tns="http://80.69.86.148/test/sync/SkynetSync.exe/";>'
     +'<SOAP:Body>'
     +'  <tns:DownloadData>'
     +'      <tns:aDocType>Country</tns:aDocType>'
     +'      <tns:aSessionId>'
     +           '8717DFD9D5E285C29247EA097B619517A52E</tns:aSessionId>'
     +'  </tns:DownloadData>'
     +'</SOAP:Body>'
     +'</SOAP:Envelope>';

     http_debug(*ON);

     rc = http_url_post_xml(
                'http://80.69.86.148/test/sync/SkynetSync.exe/'
                        +'soap/ISkynetSynchroniser'
                       : %addr(SOAP) + 2
                       : %len(SOAP)

                       : *NULL

                       : %paddr(GetInnerDoc)

                       : %addr(filename)

                       : HTTP_TIMEOUT

                       : HTTP_USERAGENT

                       : 'text/xml'

                       : 'urn:SkynetSynchroniserIntf-ISkynetSynchroniser'

                        +'#DownloadData');

     if (rc <> 1);

        http_crash();

     else;

      rc = http_parse_xml_stmf( filename

                             : HTTP_XML_CALC

                             : *null

                             : %paddr(Incoming)

                             : *null );

     if (rc <> 1);

        http_crash();

         endif;

     endif;



     *inlr = *on;



    /end-free


    *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    * GetInnerDoc():  End-element handler for HTTPAPI's XML parser.
    *                 to be called by http_url_post_xml()
    *                           or by http_parse_xml_stmf()
    *
    *                 The response from the web service contains
    *                 an "inner" XML document.  This retrieves
    *                 that document and writes it to a temporary
    *                 file in th IFS.
    *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   P GetInnerDoc     B                   export
   D GetInnerDoc     PI
   D   filename                    50a   varying
   D   depth                       10I 0 value
   D   name                      1024A   varying const
   D   path                     24576A   varying const
   D   value                             likeds(Element_Val_t)
   D   Attrs                         *   dim(32767)
   D                                     const options(*varsize)
   D fd              s             10i 0

    /free
       if name = 'return';
           fd = open( filename
                    : O_CREAT + O_TRUNC + O_WRONLY + O_CCSID
                      + O_TEXTDATA + O_TEXT_CREAT
                    : S_IRUSR + S_IWUSR
                    : 819
                    : 0 );
           // FIXME: Add error handling.
           callp write(fd: value.buf: value.len);
           callp close(fd);
       endif;
    /end-free
   P                 E

   P Incoming        B
   D Incoming        PI
   D   rate                         8F
   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 xmldata         s          30000A

    /free
          select;
          when name = 'CountryName';
       //    C_name = value;
       // when name = 'CountryCode2';
       //    FraSted= value;
       // etc... (here goes the main logic to ectract desired data...)

          endsl;
    /end-free
   P                 E
    The   "SessionId"  is hardcoded in this example (and will expire -
   after which the soap-request will fail)
   Med vennlig hilsen / Best regards
   Jan Ottar Valderhaug
   SYSTEMA AS
   St.Halvardsgt. 33A , 0192 Oslo
   Tel: +47 22660660 Mob: 47 48052470 Fax: +47 22660661

References

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