无法让PHP Soap工作

时间:2012-05-10 10:43:34

标签: php soap

我今天第一次使用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>
    )

我想在Any字符串中获取所有品牌。有人知道怎么做到这个吗?

1 个答案:

答案 0 :(得分:3)

将对象加载到simplexml

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

保存到数组中:

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

print_r($handsets);