Topic
3 replies Latest Post - ‏2013-12-22T14:57:31Z by ConstructionYard
ConstructionYard
ConstructionYard
7 Posts
ACCEPTED ANSWER

Pinned topic Parsing SOAP Envelopes

‏2013-12-17T11:11:54Z |

Hi all!

I have a critical problem and I am trying to get a solution ASAP.   I have an XML input  which contains SOAP Envelopes such as

<?xml version="1.0" encoding="UTF-8"?>
<Envelopes>

<soapenv:Envelope xmlns:sal="http://salih.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <sal:bol>
         <arg0>3</arg0>
         <arg1>532</arg1>
      </sal:bol>
   </soapenv:Body>
</soapenv:Envelope>


<soapenv:Envelope xmlns:sal="http://salih.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <sal:bol>
         <arg0>3</arg0>
         <arg1>543</arg1>
      </sal:bol>
   </soapenv:Body>
</soapenv:Envelope>

</Envelopes>

My aim is

1 .. to PARSE each soapenv:Envelope

2..  Assign this parsed soapenv:Envelope to a varible

3. use dp:url-open function to call a certain web service.

 

However I can't obtain the whole tag e.g

<soapenv:Envelope xmlns:sal="http://salih.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <sal:bol>
         <arg0>3</arg0>
         <arg1>532</arg1>
      </sal:bol>
   </soapenv:Body>
</soapenv:Envelope>

I need  that value so that I can send my soap envelopes subsequenlty in a for-each loop. Can anyone help how can I write its XSLT ?

 

Many thanks.

 

Updated on 2013-12-17T11:49:25Z at 2013-12-17T11:49:25Z by ConstructionYard
  • ted.jump
    ted.jump
    251 Posts
    ACCEPTED ANSWER

    Re: Parsing SOAP Envelopes

    ‏2013-12-17T12:02:46Z  in response to ConstructionYard

    Here's a trivial XSLT to do the parsing, there's a bunch of examples of using url-open both here on the forums and in the documentation which you should be able to combined.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:dp="http://www.datapower.com/extensions"
                    extension-element-prefixes="dp"
                    exclude-result-prefixes="dp"
                    version="1.0">
      <xsl:output method="xml" indent="yes" version="1.0"/> 
      <xsl:template match="/">
        <xsl:for-each select="Envelopes/*">
          <xsl:variable name="data" select="."/>
          <process><xsl:copy-of select="$data"/></process>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

     

    Using your input the above generates the following output

     

    <?xml version="1.0"?>
    <process>
      <soapenv:Envelope xmlns:sal="http://salih.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
          <sal:bol>
            <arg0>3</arg0>
            <arg1>532</arg1>
          </sal:bol>
        </soapenv:Body>
      </soapenv:Envelope>
    </process><process>
      <soapenv:Envelope xmlns:sal="http://salih.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
          <sal:bol>
            <arg0>3</arg0>
            <arg1>543</arg1>
          </sal:bol>
        </soapenv:Body>
      </soapenv:Envelope>
    </process>
     
  • Amit.Gera
    Amit.Gera
    34 Posts
    ACCEPTED ANSWER

    Re: Parsing SOAP Envelopes

    ‏2013-12-18T03:57:28Z  in response to ConstructionYard

    Another option is to use Advanced action 'for-each' and invoking an xslt or another processing action for each node.

  • ConstructionYard
    ConstructionYard
    7 Posts
    ACCEPTED ANSWER

    Re: Parsing SOAP Envelopes

    ‏2013-12-22T14:57:31Z  in response to ConstructionYard

    Hi Ted & Amit.

    many thanks for your response. It seems to be working ; but now I got struck on the next item with the same problem. My aim is to send my "Envelope" make a WSP SOAP call and concat the failed requests to a variable so that it can be retried.

    The WSP call part is working nicely. However , in the concat section it again fails :(. It concats the "values" again :(.

    Here is what I write on my for -each loop. (I tried many variations there )

    <xsl:for-each select="/Envelopes/soapenv:Envelope">

       <!-- introduce a variable for the current envelope -->
       <xsl:variable name="fc" select="."/>
      
    <!-- Call The Back End While Calling , Store the Request & Response. We already have the request -->
    <xsl:variable name="result">
    <dp:url-open
      .....  MY BACK END!
    >
    <xsl:copy-of select="$fc"/>
    </dp:url-open>
    </xsl:variable>


    <!-- Write the soap result down -->
    <xsl:message terminate="no" dp:priority="notice">
      <xsl:copy-of select="$result"/>
    </xsl:message>
    <!-- Did Request Reach The Backend? -->
    <xsl:choose>
    <xsl:when test="$result/url-open/responsecode='200'">
    <xsl:message terminate="no" dp:priority="info">
     SUCCESS
    </xsl:message>
      </xsl:when>
      <xsl:otherwise>
     <xsl:message terminate="no" dp:priority="info">
     FAIL... I NEED TO CONCAT The CURRENT Envelope to my variable
    </xsl:message>
    <!--  Append The Request On The Retry File -->
    BELOW ONLY CONCATS THE VALUE  such as 45 345 453 etc.
    <xsl:variable name="addEnvelope" select="concat(dp:variable('var://context/sagmer/retry'),//Envelopes[position()])"/>
    I TTRIED BELOW AS WELL

    <xsl:variable name="addEnvelope" select="concat(dp:variable('var://context/sagmer/retry'),."/>


    <xsl:message terminate="no" dp:priority="notice">
      <xsl:copy-of select="$addEnvelope"/>

    I WANT SEE  <envelope>...</envelope><envelope>...</envelope>  as each for-each iteration . ( if I receive a fault from backend.)
    </xsl:message>


    <dp:set-variable name="'var://context/sagmer/retry'" value="$addEnvelope"/>
      </xsl:otherwise>
    </xsl:choose>   

    </xsl:for-each>

     

    Many thanks!!