2013-09-28 60 views
1

我一直令人头大我的大脑摸不着头脑。我有一个从soap调用中获得的XML。我可以重复的结果,但我无法弄清楚如何通过数据在那里得到和循环。我是肥皂新手(正如你可能会说的)。试图遍历SOAP结果从卷曲

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header> 
     <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="18b2719b-e13a-41d7-ab1c-eb3319a2fd64">a588ead5-ecce-42bb-bcb3-b6f13ddc3846</ActivityId> 
    </s:Header> 
    <s:Body> 
    <GetMBDataResponse xmlns="http://blah.com/APO"> 
     <GetMBDataResult xmlns:a="http://blah.com/APO/GetGuestData" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <a:Project> 
       <a:ProjectId>12345</a:ProjectId> 
       <a:AlternateId/> 
       <a:Name>Summer Vacation</a:Name> 
       <a:Date>2014-05-17T00:00:00</a:Date> 
       <a:ProjectType/> 
       <a:Organization>My Org</a:Organization> 
      </a:Project> 
      <a:DeletedProject i:nil="true"/> 
      <a:Guests> 
       <a:MBData.BData> 
        <a:ProjectId>12345</a:ProjectId> 
        <a:BId>11979066</a:BId> 
        <a:Name>John Smith</a:Name> 
        <a:Number>101</a:Number> 
        <a:First>John</a:First> 
        <a:Last>Smith</a:Last> 
       </a:MBDData.BData> 
       <a:MBData.BData> 
        <a:ProjectId>12345</a:ProjectId> 
        <a:BId>11979067</a:BId> 
        <a:Name>Nancy Wilson</a:Name> 
        <a:Number>102</a:Number> 
        <a:First i:nil="true"/> 
        <a:Last i:nil="true"/> 
       </a:MBData.BData> 
      </a:Guests> 
     </GetMBDataResult> 
     ... 
    </GetMBDataResponse> 
</s:Envelope> 

它来自卷边返回,但我无法弄清楚如何通过MBData在那里得到和循环,并得到详细信息后,我试图simplexml_load_string($xml)。我确信这很明显,但我似乎可以得到它。

UPDATE

这是WSDL的一部分:

<xs:complexType name="Authentication"> 
    <xs:sequence> 
    <xs:element name="PartnerId" nillable="true" type="xs:string"/> 
    <xs:element name="UserName" nillable="true" type="xs:string"/> 
    <xs:element name="Password" nillable="true" type="xs:string"/> 
    </xs:sequence> 
</xs:complexType> 

你如何建立你的SoapClient的认证。我不断收到:致命错误:未捕获的SOAPFault例外:一:InternalServiceFault]未将对象引用设置到对象的实例。在/var/www/cron-gg-update.php:36堆栈跟踪:#0 /var/www/cron-gg-update.php(36):SoapClient的 - > __的SOAPCall( 'GetMBData',阵列)。

+0

不要使用卷曲的SOAP请求时有,做这一切为你:) –

回答

0

为此,您应该使用SOAP库,让你在例如数组正确的输出。

有喜欢Nusoap一些库或内部PHP Soap功能。

下面是一个PHP SOAP客户端的例子。

http://php.net/manual/en/soapclient.soapclient.php

+0

有没有办法读入通过一个数组和循环这个一个非常好的'SoapClient'类?我正在努力与PHP肥皂。了解任何基本教程? –

+0

你可以尝试这样的事情http://stackoverflow.com/questions/13929566/parse-a-soap-xml-response-with-namespaces-using-php但它更容易使用SOAP客户端) – Stony