title: Getting value from SOAP response in php
body: <p>I am getting a SOAP response for a SOAP call perfectly using SOAP ui but when I call the same in php, I am not able to traverse to the desired element(<strong>CreditId</strong> in this case), which I want.</p>
  
  <p>The following is the SOAP response that I get using SOAP ui :</p>
  
  <pre><code>&lt;soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap-env:Header/&gt;
     &lt;soap-env:Body&gt;
        &lt;n0:getProjectCreditListResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style"&gt;
           &lt;EUserGuid&gt;33/XIcx+3/GxWABQVoJXWA==&lt;/EUserGuid&gt;
           &lt;EtCurrCreditList&gt;
              &lt;item&gt;
                 &lt;PhaseId/&gt;
                 &lt;CreditcategoryDescrption&gt;Project Information Forms&lt;/CreditcategoryDescrption&gt;
                 &lt;CreditId&gt;CSD1GSP1L-1000008140&lt;/CreditId&gt;
              &lt;/item&gt;
              &lt;item&gt;
                 &lt;PhaseId/&gt;
                 &lt;CreditcategoryDescrption&gt;Project Information Forms&lt;/CreditcategoryDescrption&gt;
                 &lt;CreditId&gt;CSD1GSP2L-1000008140&lt;/CreditId&gt;
              &lt;/item&gt;
  &lt;/EtCurrCreditList&gt;
           &lt;EtErrorLogInfo/&gt;
        &lt;/n0:getProjectCreditListResponse&gt;
     &lt;/soap-env:Body&gt;
  &lt;/soap-env:Envelope&gt;
  </code></pre>
  
  <p>Now I have gone through the various similar questions on the site, where it is advised to do like this to get the desired element :</p>
  
  <pre><code>$client = new SoapClient('wsdl file path',array('trace'=&gt;1,'exceptions'=&gt;1);
  $res = $client-&gt;getCreditFormDataXml(array(input arguments));
  
      $xml = simplexml_load_string($res);
      $xml-&gt;registerXPathNamespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
      $xml-&gt;registerXPathNamespace('n0', 'urn:sap-com:document:sap:soap:functions:mc-style');
      foreach ($xml-&gt;xpath('//EtCurrCreditList//item//CreditId') as $item)
      {
          var_dump($item);
      }
  </code></pre>
  
  <p>However I get an error stating that </p>
  
  <blockquote>
    <p>Warning: simplexml_load_string() expects parameter 1 to be string</p>
  </blockquote>
  
  <p>I have tried converting the <strong>$res</strong> variable to a string but it gives an error that </p>
  
  <blockquote>
    <p>Object of class stdClass could not be converted to string</p>
  </blockquote>
  
  <p>But if I do <strong>var_dump($res)</strong>, I get output like this :</p>
  
  <pre><code>object(stdClass)[2]
    public 'EUserGuid' =&gt; string 'ß×!Ì~ßñ±X�PV‚WX' (length=16)
    public 'EtCurrCreditList' =&gt; 
      object(stdClass)[3]
    public 'EtErrorLogInfo' =&gt; 
      object(stdClass)[4]
  </code></pre>
  
  <p><strong>Why is the code not going to the sub nodes of the EtCurrCreditList so that I can then process it to get the desired value.</strong> - Solved</p>
  
  <p>Final Output : </p>
  
  <pre><code>stdClass Object
  (
      [EUserGuid] =&gt; ß×!Ì~ßñ±XPV‚WX
      [EtCurrCreditList] =&gt; stdClass Object
          (
              [item] =&gt; Array
                  (
                      [0] =&gt; stdClass Object
                          (
                              [PhaseId] =&gt; 
                              [PhaseDescription] =&gt; 
                              [CreditcategoryId] =&gt; CSD1GSL-1000008140
                              [CreditcategoryDescrption] =&gt; Project Information Forms
                              [CreditId] =&gt; CSD1GSP1L-1000008140
                           )
              [1] =&gt; stdClass Object
                          (
                              [PhaseId] =&gt; 
                              [PhaseDescription] =&gt; 
                              [CreditcategoryId] =&gt; CSD1GSL-1000008140
                              [CreditcategoryDescrption] =&gt; Project Information Forms
                              [CreditId] =&gt; CSD1GSP2L-1000008140
              )
              [2] =&gt; stdClass Object
                          (
                              [PhaseId] =&gt; 
                              [PhaseDescription] =&gt; 
                              [CreditcategoryId] =&gt; CSD1GSL-1000008140
                              [CreditcategoryDescrption] =&gt; Project Information Forms
                              [CreditId] =&gt; CSD1GSP3L-1000008140
              )
          )
  
          )
  
      [EtErrorLogInfo] =&gt; stdClass Object
          (
          )
  </code></pre>