title: How do I read the soap response from UPS web services?
body: <p>I am trying to parse the UPS sample code for the Rating service and while I get the response from UPS, I cannot seem to do anything with it. How do I read through and find the data I want? eg </p>
  
  <pre><code>&lt;rate:RatedShipment&gt;&lt;rate:Service&gt;&lt;rate:Code&gt;03&lt;/rate:Code&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&lt;rate:TotalCharges&gt;
     &lt;rate:CurrencyCode&gt;USD&lt;/rate:CurrencyCode&gt;
     &lt;rate:MonetaryValue&gt;126.72&lt;/rate:MonetaryValue&gt;
  &lt;/rate:TotalCharges&gt;
  </code></pre>
  
  <p>I need that code and the total charges.
  My code so far looks like this:</p>
  
  <pre><code>        $result = $client-&gt;__soapCall($operation ,array($this-&gt;processRate()));
          $resp = $client-&gt;__getLastResponse() ;
          echo $resp ;
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soapenv:Header /&gt;
    &lt;soapenv:Body&gt;
      &lt;rate:RateResponse xmlns:rate="http://www.ups.com/XMLSchema/XOLTWS/Rate/v1.1"&gt;
        &lt;common:Response xmlns:common="http://www.ups.com/XMLSchema/XOLTWS/Common/v1.0"&gt;
          &lt;common:ResponseStatus&gt;
            &lt;common:Code&gt;1&lt;/common:Code&gt;
            &lt;common:Description&gt;Success&lt;/common:Description&gt;
          &lt;/common:ResponseStatus&gt;
          &lt;common:Alert&gt;
            &lt;common:Code&gt;110971&lt;/common:Code&gt;
            &lt;common:Description&gt;Your invoice may vary from the displayed reference rates&lt;/common:Description&gt;
          &lt;/common:Alert&gt;
          &lt;common:Alert&gt;
            &lt;common:Code&gt;110920&lt;/common:Code&gt;
            &lt;common:Description&gt;Ship To Address Classification is changed from Residential to Commercial&lt;/common:Description&gt;
          &lt;/common:Alert&gt;
          &lt;common:TransactionReference /&gt;
        &lt;/common:Response&gt;
        &lt;rate:RatedShipment&gt;
          &lt;rate:Service&gt;
            &lt;rate:Code&gt;03&lt;/rate:Code&gt;
            &lt;rate:Description /&gt;
          &lt;/rate:Service&gt;
          &lt;rate:RatedShipmentAlert&gt;
            &lt;rate:Code&gt;110971&lt;/rate:Code&gt;
            &lt;rate:Description&gt;Your invoice may vary from the displayed reference rates&lt;/rate:Description&gt;
          &lt;/rate:RatedShipmentAlert&gt;
          &lt;rate:RatedShipmentAlert&gt;
            &lt;rate:Code&gt;110920&lt;/rate:Code&gt;
            &lt;rate:Description&gt;Ship To Address Classification is changed from Residential to Commercial&lt;/rate:Description&gt;
          &lt;/rate:RatedShipmentAlert&gt;
          &lt;rate:BillingWeight&gt;
            &lt;rate:UnitOfMeasurement&gt;
              &lt;rate:Code&gt;LBS&lt;/rate:Code&gt;
              &lt;rate:Description&gt;Pounds&lt;/rate:Description&gt;
            &lt;/rate:UnitOfMeasurement&gt;
            &lt;rate:Weight&gt;3.0&lt;/rate:Weight&gt;
          &lt;/rate:BillingWeight&gt;
          &lt;rate:TransportationCharges&gt;
            &lt;rate:CurrencyCode&gt;USD&lt;/rate:CurrencyCode&gt;
            &lt;rate:MonetaryValue&gt;17.76&lt;/rate:MonetaryValue&gt;
          &lt;/rate:TransportationCharges&gt;
          &lt;rate:ServiceOptionsCharges&gt;
            &lt;rate:CurrencyCode&gt;USD&lt;/rate:CurrencyCode&gt;
            &lt;rate:MonetaryValue&gt;0.00&lt;/rate:MonetaryValue&gt;
          &lt;/rate:ServiceOptionsCharges&gt;
          &lt;rate:TotalCharges&gt;
            &lt;rate:CurrencyCode&gt;USD&lt;/rate:CurrencyCode&gt;
            &lt;rate:MonetaryValue&gt;17.76&lt;/rate:MonetaryValue&gt;
          &lt;/rate:TotalCharges&gt;
        &lt;/rate:RatedShipment&gt;
        ......
      &lt;/rate:RateResponse&gt;
    &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>I then run this code on it:</p>
  
  <pre><code>$xml = simplexml_load_string($resp);
  \TYPO3\Flow\var_dump($xml  );  
  
  $json = json_encode($xml);
  $xmlarray = json_decode($json,TRUE);
  
  echo "\n".__FILE__.' '.__LINE__."   xmlarray   \n";  
  \TYPO3\Flow\var_dump($xmlarray);
  die;
  </code></pre>
  
  <p>This outputs </p>
  
  <pre><code>    &lt;div class="Flow-Error-Debugger-VarDump Flow-Error-Debugger-VarDump-Floating"&gt;
              &lt;div class="Flow-Error-Debugger-VarDump-Top"&gt;
                  Flow Variable Dump
              &lt;/div&gt;
              &lt;div class="Flow-Error-Debugger-VarDump-Center"&gt;
                  &lt;pre dir="ltr"&gt;&lt;span class="debug-object debug-unregistered" title="00000000366333b30000000074e4ee7f"&gt;SimpleXMLElement&lt;/span&gt;&lt;span class="debug-scope"&gt;prototype&lt;a id="o00000000366333b30000000074e4ee7f"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span class="debug-ptype" title="unknown"&gt;object&lt;/span&gt;&lt;/pre&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  /home/me/domains/shop.me.com/public_html/releases/20131219160416/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Shop_Shipping_UPSShippingHandler.php 336   xmlarray   
  
          &lt;div class="Flow-Error-Debugger-VarDump Flow-Error-Debugger-VarDump-Floating"&gt;
              &lt;div class="Flow-Error-Debugger-VarDump-Top"&gt;
                  Flow Variable Dump
              &lt;/div&gt;
              &lt;div class="Flow-Error-Debugger-VarDump-Center"&gt;
                  &lt;pre dir="ltr"&gt;array(empty)&lt;/pre&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Seems my <code>simplexml_load_string($resp)</code> call is not working.</p>
  
  <p>UPDATE:
  Thanks alien. This is what my code looks like now - it is not perfect yet but you get the idea - :</p>
  
  <pre><code>                $result = $client-&gt;__soapCall($operation ,array($this-&gt;processRate()));                 
                  $resp =   $client-&gt;__getLastResponse() ; 
                  $sxe = simplexml_load_string($resp);
                  $sxe-&gt;registerXPathNamespace('r', "http://www.ups.com/XMLSchema/XOLTWS/Rate/v1.1");
                  $codes = $sxe-&gt;xpath('//r:RatedShipment/r:Service/r:Code');
  
                  $mv = $sxe-&gt;xpath('//r:TotalCharges/r:MonetaryValue');
                  $indx=0;
                  $estimates = array();
                  foreach ($codes as $c) {
                      $temporaryEstimate = array();
                      $temporaryEstimate['estimateId'] = $this-&gt;getServiceTitleByCode($c-&gt;__toString());
                      $temporaryEstimate['estimatePrice'] = '$' .$mv[$indx];
                      $estimates[] = $temporaryEstimate;                    
                      $indx++;
                  }
                  return $estimates;
  </code></pre>