2012-05-10 206 views
0

今天我第一次使用Soap。但知道我需要獲得一個陣列中的所有品牌。肥皂以字符串形式返回。無法讓PHP Soap正常工作

我使用我的代碼:

<?php 
$soapClient = new SoapClient("http://getmoxecure.com:5454/ProductService.asmx?wsdl"); 

    $result = $soapClient->getHandsetBrands(); 
    print_r($result->getHandsetBrandsResult); 
    ?> 

這樣做的結果是:

stdClass Object 
(

     [schema] => <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="HandsetBrandTable"><xs:complexType><xs:sequence><xs:element name="handset_brand" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema> 
     [any] => <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><NewDataSet xmlns=""><HandsetBrandTable diffgr:id="HandsetBrandTable1" msdata:rowOrder="0"><handset_brand>Android</handset_brand></HandsetBrandTable><HandsetBrandTable diffgr:id="HandsetBrandTable2" msdata:rowOrder="1"><handset_brand>BlackBerry</handset_brand></HandsetBrandTable><HandsetBrandTable diffgr:id="HandsetBrandTable3" msdata:rowOrder="2"><handset_brand>LG</handset_brand></HandsetBrandTable><HandsetBrandTable diffgr:id="HandsetBrandTable4" msdata:rowOrder="3"><handset_brand>Nokia</handset_brand></HandsetBrandTable><HandsetBrandTable diffgr:id="HandsetBrandTable5" msdata:rowOrder="4"><handset_brand>Samsung</handset_brand></HandsetBrandTable><HandsetBrandTable diffgr:id="HandsetBrandTable6" msdata:rowOrder="5"><handset_brand>Sony Ericsson</handset_brand></HandsetBrandTable></NewDataSet></diffgr:diffgram> 
    ) 

我想所有的品牌在任何字符串。有人知道如何得到這個?

回答

3

負載對象變成simplexml的

$xml = simplexml_load_string($result->getHandsetBrandsResult->any); 

保存到數組:

$hansets = array(); 
foreach ($xml->NewDataSet->HandsetBrandTable as $handset) $handsets[] = $handset->handset_brand; 

print_r($handsets);