0

我今天第一次使用 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 字符串中的所有品牌。有人知道如何得到这个吗?

4

1 回答 1

3

load the object into simplexml

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

save into an array:

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

print_r($handsets);
于 2012-05-10T12:03:08.233 回答