I am trying to parse SOAP response to JSON. So far I have this code:
$data = '<?xml version="1.0" encoding="utf-8"?>';
$data .= '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
$data .= '<soap12:Body>';
$data .= '<GetCommunities xmlns="url">';
$data .= '<APIUsername>string</APIUsername>';
$data .= '<APIPassword>string</APIPassword>';
$data .= '</GetCommunities>';
$data .= '</soap12:Body>';
$data .= '</soap12:Envelope>';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "url" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $data);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($data) ));
$result = curl_exec($soap_do);
echo $result;
This code is working and I am getting following result:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCommunitiesResponse xmlns="url">
<GetCommunitiesResult>
<Communities>
<CommunityID>1</CommunityID>
<CommunityName> Not Specified</CommunityName>
</Communities>
<Communities>
<CommunityID>276</CommunityID>
<CommunityName>Bella Toscana</CommunityName>
</Communities>
<Communities>
<CommunityID>31</CommunityID>
<CommunityName>Crescent Lakes</CommunityName>
</Communities>
<Communities>
<CommunityID>62</CommunityID>
<CommunityName>Hillcrest Estate</CommunityName>
</Communities>
<Communities>
<CommunityID>750</CommunityID>
<CommunityName>Sunny Beach</CommunityName>
</Communities>
<Communities>
<CommunityID>124</CommunityID>
<CommunityName>Terra Verde Resort</CommunityName>
</Communities>
<Communities>
<CommunityID>744</CommunityID>
<CommunityName>The Dales at West Haven</CommunityName>
</Communities>
<Communities>
<CommunityID>158</CommunityID>
<CommunityName>Westridge</CommunityName>
</Communities>
</GetCommunitiesResult>
</GetCommunitiesResponse>
</soap:Body>
</soap:Envelope>
I need to create JSON response from the data which can be found between GetCommunitiesResult tags. How can I do this?
Edited and tested
// a bit of a hack, but let's see...
list($trash,$result)=explode('<soap:Body>',$result);
list($result,$trash)=explode('</soap:Body>',$result);
unset($trash);
$result=str_replace('xmlns="url"','',$result);
$simple_result=simplexml_load_string($result);
$json_result=json_encode($simple_result);
//var_export($simple_result);
echo $json_result;
Output:
{"GetCommunitiesResult":{"Communities":[{"CommunityID":"1","CommunityName":"
Not Specified"},{"CommunityID":"276","CommunityName":"Bella
Toscana"},{"CommunityID":"31","CommunityName":"Crescent
Lakes"},{"CommunityID":"62","CommunityName":"Hillcrest
Estate"},{"CommunityID":"750","CommunityName":"Sunny
Beach"},{"CommunityID":"124","CommunityName":"Terra Verde
Resort"},{"CommunityID":"744","CommunityName":"The Dales at West
Haven"},{"CommunityID":"158","CommunityName":"Westridge"}]}}
Related
This is the response of the soap request.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetConfigurationInfoResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://micros-hosting.com/EGateway/">
<configInfoResponse>
<OperationalResult>
<Success>true</Success>
<ErrorCode>Success</ErrorCode>
<ErrorMessage>Success</ErrorMessage>
</OperationalResult>
<ConfigInfoType>
<EConfigurationInfoType>MENUITEMDEFINITIONS</EConfigurationInfoType>
</ConfigInfoType>
**<MenuItemDefinitions><?xml version="1.0" encoding="utf-8"?><?micros-type Micros.PosCore.DataStore.DbRecords.DbMenuItemDefinition[], PosCore, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null?><ArrayOfDbMenuItemDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><DbMenuItemDefinition><NameOptions>0000000</NameOptions><MenuItemDefID>4055</MenuItemDefID><HierStrucID>25</HierStrucID><MenuItemMasterID>1570</MenuItemMasterID><SequenceNum>1</SequenceNum><Name1><StringNumberId>8507</StringNumberId><StringText>=Breakfast=</StringText></Name1><Name2><StringNumberId>8508</StringNumberId><StringText /></Name2><SluSort>0</SluSort><NluNumber>0</NluNumber><Tare>0</Tare><Surcharge>0</Surcharge><IconNumber>0</IconNumber><OptionBits>00000000</OptionBits><SpecialCount>0</SpecialCount><PrepTime>0</PrepTime><Name3><StringNumberId>0</StringNumberId><StringText /></Name3><LongDescriptor><StringNumberId>0</StringNumberId><StringText /></LongDescriptor><MenuItemClassObjNum>0</MenuItemClassObjNum><NluGroupIndex>0</NluGroupIndex><SluIndex>0</SluIndex><HhtSluIndex>0</HhtSluIndex><MainLevels>00000000</MainLevels><SubLevels>00000000</SubLevels><PosRef>0</PosRef><PrintClassObjNum>0</PrintClassObjNum><PrefixLevelOverride>0</PrefixLevelOverride><GuestCount>0</GuestCount><MenuLevelEntries /><DefaultCondiments /><NextScreen /><MiMasterObjNum>10010000</MiMasterObjNum><CheckAvailability>false</CheckAvailability><OutOfMenuItem>false</OutOfMenuItem></DbMenuItemDefinition><DbMenuItemDefinition;</ArrayOfDbMenuItemDefinition></MenuItemDefinitions>**
</configInfoResponse>
</GetConfigurationInfoResponse>
</soap:Body>
</soap:Envelope>
How can I get value from this <MenuItemDefinitions></MenuItemDefinitions>? This xml element inside another XML data. How to say this kind of XML?
How to filter that value using PHP? I only need get value from the inside <MenuItemDefinitions></MenuItemDefinitions> xml value.
This is the soap request php code.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.5.10:8080/EGateway/SimphonyPosApiWeb.asmx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body>
<GetConfigurationInfo>
<vendorCode />
<employeeObjectNum>10009</employeeObjectNum>
<configurationInfoType>
<int>1</int>
</configurationInfoType>
<revenueCenter>5</revenueCenter>
<configInfoResponse />
</GetConfigurationInfo>
</soap:Body>
</soap:Envelope>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: text/xml;",
"SOAPAction: http://192.168.5.10:8080/EGateway/GetConfigurationInfo"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
I need to publish PHP variable values on SOAP-based web service some how I am not able to convert PHP POST values in XML elements.
How can I get POST variable, say abc, in sName element?
My code in PHP
<?php
//session_start();
$server_name= abc;
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<createtest xmlns="http://tempuri.org/">
<sA>ADD</sA>
<sType>service</sType>
<sName>"$server_name"</sName>
</createtest>
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-Type: text/xml; charset=utf-8",
"Host: http://example.com",
"Content-length: ".strlen($xml_post_string),
"SOAPAction: http://tempuri.org/createtest"
);
url = 'http://example.com'; // WSDL web service url for request
method/function
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP
request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo $response = curl_exec($ch);
?>
You have to put quotes around abc, when you define the variable as a string:
$server_name = "abc";
And you could also put the variable in the string like this to make it easier to understand it as a variable in such a long string:
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<createtest xmlns="http://tempuri.org/">
<sA>ADD</sA>
<sType>service</sType>
<sName>'.$server_name.'</sName>
</createtest>
</soap:Body>
</soap:Envelope>';
XML response want to convert into PHP array it works fine in $response but when I convert into an array it will become empty. How can I convert this XML into an array to display it on the web page? Any information that would point me in the correct direction would be great.
$soapUrl = "http://api.rlcarriers.com/1.0.2/RateQuoteService.asmx"; // asmx URL of WSDL
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetRateQuote xmlns="http://www.rlcarriers.com/">
<APIKey>UtN0YWEGRhOjNiNmItODRkMS00NzgyLThiYzNTViEzNjODNmC</APIKey>
<request>
<QuoteType>Domestic</QuoteType>
<CODAmount>0</CODAmount>
<Origin>
<City>New York</City>
<StateOrProvince>NY</StateOrProvince>
<ZipOrPostalCode>10001</ZipOrPostalCode>
<CountryCode>USA</CountryCode>
</Origin>
<Destination>
<City>New York</City>
<StateOrProvince>NY</StateOrProvince>
<ZipOrPostalCode>10009</ZipOrPostalCode>
<CountryCode>USA</CountryCode>
</Destination>
<Items>
<Item>
<Class>150.0</Class>
<Weight>2.5</Weight>
<Width>2.5</Width>
<Height>2.5</Height>
<Length>2.1</Length>
</Item>
</Items>
<DeclaredValue>120</DeclaredValue>
<Accessorials>
<Accessorial>ResidentialPickup</Accessorial>
<Accessorial>ResidentialDelivery</Accessorial>
</Accessorials>
<OverDimensionPcs>0</OverDimensionPcs>
</request>
</GetRateQuote>
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: http://www.rlcarriers.com/GetRateQuote",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);exit;
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
print_r($array);
Below is the response received from the above code.
string(4037) "trueNEW YORKNY10001USANEW YORKNY10009USALISLong Island,
NY113781-888-575-2632MASPETHNYLISLong Island,
NY113781-888-575-2632MASPETHNY$420.352$442.90$8.86MINIMUM$510.35DISCNTFloor$420.35DISCNF$90.00FUEL23.1%$20.79ARBMH$65.00RPUCWT$132.30RCCWT$132.30NET$440.39STD71825391$839.95$440.39GSDS297780121$38.90$479.29GSAM382622281$77.70$518.09"
Those are SOAP XML, change it's heading by
...
// converting
$response = curl_exec($ch);
curl_close($ch);
$clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $response);
$xml = simplexml_load_string($clean_xml);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
print_r($array);
see: How to parse SOAP XML?
I'm looking for a way to send a SOAP request from PHP code. An online game called MovieStarPlanet, has a "library" with many SOAP requests.
Here is the link to all queries:
http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx
The WSDL description:
http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL
The query is like this:
POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1
Host: http://www.moviestarplanet.fr
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://moviestarplanet.com/Login"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
<ThirdPartyToken>string</ThirdPartyToken>
</ThirdPartyTokenHeader>
</soap:Header>
<soap:Body>
<Login xmlns="http://moviestarplanet.com/">
<username>string</username>
<password>string</password>
</Login>
</soap:Body>
</soap:Envelope>
And the answer to this query is:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ThirdPartyTicketHeader xmlns="http://moviestarplanet.com/">
<Ticket>string</Ticket>
</ThirdPartyTicketHeader>
</soap:Header>
<soap:Body>
<LoginResponse xmlns="http://moviestarplanet.com/">
<LoginResult>
<ServiceResult>
<Codee>int</Codee>
<Description>string</Description>
</ServiceResult>
<ActorId>int</ActorId>
<AppToken>string</AppToken>
<UserInfo>
<FriendCount>int</FriendCount>
<MembershipTimeoutDate>dateTime</MembershipTimeoutDate>
<VipTier>int</VipTier>
<Level>int</Level>
<LockedUntil>dateTime</LockedUntil>
<LockedText>string</LockedText>
<SkinSWF>string</SkinSWF>
<LastLogin>dateTime</LastLogin>
</UserInfo>
</LoginResult>
</LoginResponse>
</soap:Body>
</soap:Envelope>
That would suggest a lot of account information when the username/password combination is correct.
I did a lot of research, but I don't know how to apply the code. Here's what I did:
$soap_request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$soap_request .= "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
$soap_request .= " <soap:Header>\n";
$soap_request .= " <ThirdPartyTokenHeader xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= " <ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>\n";
$soap_request .= " </ThirdPartyTokenHeader>\n";
$soap_request .= " </soap:Header>\n";
$soap_request .= " <soap:Body>\n";
$soap_request .= " <Login xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= " <username>string</username>\n";
$soap_request .= " <password>string</password>\n";
$soap_request .= " </Login>\n";
$soap_request .= " </soap:Body>\n";
$soap_request .= "</soap:Envelope>";
$header = array(
"POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
"Host: http://www.moviestarplanet.fr",
"Content-type: text/xml; charset=utf-8",
"Content-length: ".strlen($soap_request),
"SOAPAction: \"http://moviestarplanet.com/Login\"",
);
$url = "http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL";
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
print 'Success.';
}
When I run the code, it tells me an error: "Operation timed out after 10000 milliseconds with 0 bytes received".
Anyone can help me?
You are connecting to the wsdl file in your curl call. (
$url = "http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL")
The wsdl is NOT the webservice, the wsdl is a xml file with a description of the webservice.
Insted of doing all the low level coding using curl, you could use the SoapClient class:
$client=new SoapClient('http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL');
That way a lot of the basic communication with then webservice is handle automatic.
For example, you can start by listing all services on site:
print_r($client->__getFunctions());
I have found the soltuion! :)
<?php
$xml_data = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
<ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>
</ThirdPartyTokenHeader>
</soap:Header>
<soap:Body>
<Login xmlns="http://moviestarplanet.com/">
<username>USER</username>
<password>PASS</password>
</Login>
</soap:Body>
</soap:Envelope>
';
$headers = array(
"POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
"Referer: www.moviestarplanet.fr",
"User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9505 Build/KOT49H)",
"Content-Type: text/xml; charset=utf-8",
"Host: www.moviestarplanet.fr",
"Content-length: ".strlen($xml_data),
"Expect: 100-continue"
);
$url = 'http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$reply = curl_exec($ch);
echo($reply);
?>
I use the code below to get xml data from some API:
<?php
$ch = curl_init();
$xml = '<?xml version="1.0" encoding="utf-8"><file><auth>myapikey</auth><warenhouse/></file>';
curl_setopt($ch, CURLOPT_URL, 'http://somesite.com/xml.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
?>
I get xml data successfully something like
<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseCode>200</responseCode>
<result>
<whs>
<warenhouse>
<city>New York City</city>
<address>Some Address</address>
<number>1</number>
<phone>1111111</phone>
</warenhouse>
<warenhouse>
...
</warenhouse>
</whs>
</result>
</response>
</xml>
but I can't parse and echo only cities using
$parser = simplexml_load_string($response);
foreach($parser->warenhouse as $item) {
echo $item->city;
}
What's wrong?
Your XML is a bit malformed , remove that </xml> from the end.
You need to loop like this
foreach ($xml->result->whs->warenhouse as $child)
{
echo $child->city;
}
The code..
<?php
$xml= <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<responseCode>200</responseCode>
<result>
<whs>
<warenhouse>
<city>New York City</city>
<address>Some Address</address>
<number>1</number>
<phone>1111111</phone>
</warenhouse>
<warenhouse>
</warenhouse>
</whs>
</result>
</response>
XML;
$xml = simplexml_load_string($xml);
foreach ($xml->result->whs->warenhouse as $child)
{
echo $child->city;
}
OUTPUT:
New York City
Demo