1

I have been wracking my brain to figure this out. I have an XML that get from a soap call. I can echo the result but I can't figure out how to get in there and loop through the data. I'm new to soap (as you might tell).

<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>

I've tried to simplexml_load_string($xml) after it's returned from the cURL but I can't figure out how to get in there and loop through the MBData and get the details. I'm sure it's obvious but I just can seem to get it.

UPDATE

This is part of the 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>

How would you build your SoapClient authentication. I keep getting: Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in /var/www/cron-gg-update.php:36 Stack trace: #0 /var/www/cron-gg-update.php(36): SoapClient->__soapCall('GetMBData', Array).

M Charles
  • 165
  • 1
  • 1
  • 14

1 Answers1

0

For this you should use a SOAP Library which gives you the correct output in an array for example.

There are some libs like Nusoap or the internal PHP Soap functions.

Here is an example for a PHP Soap client.

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

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • There's no way to read this into an array and loop through it? I'm struggling with PHP Soap. Know of any basic tutorials? – M Charles Sep 29 '13 at 00:08
  • You could try something like this http://stackoverflow.com/questions/13929566/parse-a-soap-xml-response-with-namespaces-using-php but its much easier to use a soap clients ;) – René Höhle Sep 29 '13 at 11:02