ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Problem reading Xml response from a Soap Web Service

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem reading Xml response from a Soap Web Service

    Hi all

    I?m try to read Xml response from a Soap Web service invoked via http_url_post_stmf, with xmlReader form PowerExt (Henrik Rützou).

    In the response i find characters like &lt &gt ? ect ; question : this characters, can cause problem to xmlReader ? if yes how can i avoid the problem and how can replace this characters from the Web Service response ?

    Thanks in advance

    Gio
    Example of a part of response Xml :

    Xml Response example:
    <code xsi:type="xsd:int">0</code>
    <message xsi:type="xsd:string" />
    <response xsi:type="xsd:string">&lt;?xml version="1.0"
    encoding="UTF-8" standalone="no" ?&gt;&lt;documenti&gt;&lt;documento
    id="identificativo esterno"
    file="my.xml"&gt;&lt;sospeso&gt;N&lt;/sospeso&gt;&lt;stato&gt;DV&lt;/stato&g
    t;&lt;esito&gt;OK&lt;/esito&gt;&lt;segnalazione&gt;R&lt;/segnalazione&gt;&lt
    ;dettaglioSegnalazione&gt;Dati del trasmittente
    modificati&lt;/dettaglioSegnalazione&gt;&lt;/documento&gt;&lt;/documenti&gt;
    </response>
    <token
    xsi:type="xsd:string">gtkcsneobm-ergbnngahb-tqtlcpgowt</token>

  • #2
    I think you'd have to ask Henrik how to use xmlReader, I am not familiar with it.

    Comment


    • #3
      Originally posted by Scott Klement View Post
      I think you'd have to ask Henrik how to use xmlReader, I am not familiar with it.
      Hi Scott thanks for your reply ..

      A question: do you have other solution/suggestions for reading Xml response also for avoid the characters like &lt-&gt etc . (some utility that convert this characters &lt-&gt in <> when http_url_post_stmf receive the response or other way to parse this response ..?? )

      Thanks

      Comment


      • #4
        I'm in a hurry or I would look it up for you - but I'm fairly certain that Henrik has answered this question on other lists. I suspect it would have been RPG400 or WEB400 on midrange.com. A google search might find it.

        Comment


        • #5
          Hi JobBoy

          I found this links from Henrik :

          1- http://www.scottklement.com/archives.../msg00015.html
          here he says:
          "Scott has a build in XML reader in HTTPAPI, why not use that. The alternative is either to use XML-INTO or my free build in XMLreader() in powerEXT Core that work both as an include in the HTTPAPI program and in a and alone environment with input typical from a file. They will all handle the special XML decodings like &amp; automatically."
          But i don't know what means "They will all handle the special XML decodings like &amp "

          2-
          http://www.code400.com/forum/forum/tips-techniques-tools-announcements/iseries-tools/9212-read-xml-smarter-in-just-3-5-rpgle-statements-powerext-core-v-1-2
          here i read : "* Decodes encoded special characters"
          also here i don't know what means "Decodes encoded special characters"

          if some can help me to understand .. i will be gratefull .. also some other parser/reader that let me solce this problem will be welcome

          Thanks in advance


          Comment


          • #6
            I noticed , that if i invoke the web service with soapUi, in the response, i find "<" and ">" instead of &lt and &gt and i find also "[CDATA" that in the As400 response via

            LIBHTTP/http_url_post_stmf i don't see .. pheraps i'm wrong on invoking Web Service Thanks ... <sendDocumentReturn xsi:type="ns1:VReturn"> <code xsi:type="xsd:int">0</code> <message xsi:type="xsd:string"/> <response xsi:type="xsd:string"><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no" ?><documenti><documento id="identificativo" file="myfile.xml"><sospeso>N</sospeso><state>X</stato><esito>OK</esito><segnalazione>R</segnalazione><dettaglioSegnalazione>Dati del trasmittente modificati</dettaglioSegnalazione></documento></documenti>]]></response> <token xsi:type="xsd:string">xxxxxxxxx</token> </sDocumentReturn> </ns1:sDocumentResponse>

            Comment


            • #7
              In case it is unclear (I don't know why it would be) what you have here is two XML documents.

              The first looks like this:
              Code:
              <code xsi:type="xsd:int">0</code>
              <message xsi:type="xsd:string" />
              <response xsi:type="xsd:string"> ANY STRING CAN GO HERE </response>
              <token xsi:type="xsd:string">gtkcsneobm-ergbnngahb-tqtlcpgowt</token>
              The second document is stored as a character string inside the "response" element and looks like this:
              Code:
              &lt;?xml version="1.0"
              encoding="UTF-8" standalone="no" ?&gt;&lt;documenti&gt;&lt;documento
              id="identificativo esterno"
              file="my.xml"&gt;&lt;sospeso&gt;N&lt;/sospeso&gt;&lt;stato&gt;DV&lt;/stato&g
              t;&lt;esito&gt;OK&lt;/esito&gt;&lt;segnalazione&gt;R&lt;/segnalazione&gt;&lt
              ;dettaglioSegnalazione&gt;Dati del trasmittente
              modificati&lt;/dettaglioSegnalazione&gt;&lt;/documento&gt;&lt;/documenti&gt;
              Because this XML is sent inside another XML document as a character string, any special characters need to be escaped while it is inside that document. So the < and > characters become &lt; and &gt;.

              SoapUI is rewriting it to make it easier for you to understand by using <![CDATA[ -- but it means the exact same thing.

              In either case, you have to process this as two separate documents.

              1) Parse the original ("outer") document and save the contents of "response" into a string.
              2) Parse the inner document by parsing the string you saved in step 1.

              Step 1 will convert all of the &lt; and &gt; back to < and > characters so that step 2 will process the second document correctly.

              This is a very common situation with SOAP web services, there are millions of web services that work this way.

              Comment


              • #8
                Hi Scott
                thanks again for you reply ..

                be patient .. can i find some example in your LIBHTTP or in other link that i can follow to menage this situation ?

                Thanks in advance for your help

                Gio

                Comment


                • #9
                  There is an example at the following link -- though, I don't know if this web service is still available (I haven't tried this code in many years) but the code should illustrate the idea:

                  Comment

                  Working...
                  X