var_dump and xml result

i am seleting data from webservice using php code… but i get data in string.
i tested it in the website

I entered the link of myservice which is http://196.218.16.133/onlinereservation/service.asmx?WSDL
and i go to hotelsearch function and paste in HotelData this XML code


<HotelsParameters><CityID>388</CityID><UserName>admin</UserName><UserPassword>admin</UserPassword><DateFrom>12/04/2010</DateFrom><DateTo>13/04/2010</DateTo><NumberOfRooms>2</NumberOfRooms><CurrencyID>162</CurrencyID><Room><RoomSerial>1</RoomSerial><Adults>1</Adults><Child><ChildSerial>1</ChildSerial><ChildAge>5</ChildAge></Child></Room><Room><RoomSerial>2</RoomSerial><Adults>2</Adults><Child><ChildSerial>1</ChildSerial><ChildAge>8</ChildAge></Child><Child><ChildSerial>2</ChildSerial><ChildAge>5</ChildAge></Child></Room></HotelsParameters>

and it produce XML Result

all that i need is to get it using my code, i use var_dump($result) but it did not produce XML file, it produce string

how to produce XML file using another funtion that var_dump()
MY code is


<?
$dom = new DOMDocument("1.0");

// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// Call the Cdyne result Service. Debugging mode enabled (e.g. 'trace'=>true)
$client = new SOAPClient('http://196.218.16.133/onlinereservation/service.asmx?WSDL');

try {
	$params->HotelData = '<HotelsParameters><CityID>388</CityID><UserName>admin</UserName><UserPassword>admin</UserPassword><DateFrom>12/04/2010</DateFrom><DateTo>13/04/2010</DateTo><NumberOfRooms>2</NumberOfRooms><CurrencyID>162</CurrencyID><Room><RoomSerial>1</RoomSerial><Adults>1</Adults><Child><ChildSerial>1</ChildSerial><ChildAge>5</ChildAge></Child></Room><Room><RoomSerial>2</RoomSerial><Adults>2</Adults><Child><ChildSerial>1</ChildSerial><ChildAge>8</ChildAge></Child><Child><ChildSerial>2</ChildSerial><ChildAge>5</ChildAge></Child></Room></HotelsParameters>';	// set up parameters to pass. If we need multiple
				// parameters, we can add additional elements to
				// the array: $params->City = 'Dublin'
				
	$result = $client->HotelsSearch($params);
	//echo $result;
} catch (SOAPFault $exception) {
	// if we hit an error, print the exception and the XML we sent
	print $exception;
	print htmlspecialchars($client->__getLastRequest());
//	exit;
}

var_dump($result);
?>


  1. What’s $params? It looks like an object, but where is it initialized? What kind of an object is it anyway?

  2. I tried testing your web service with the site you gave a link to, but it didn’t work at all with your sample data. In particular, the error message was “Server was unable to process request. —> Column ‘HotelCode’ does not belong to table HotelsParameters.”, which is somewhat surprising, since HotelCode doesn’t appear to be part of the request.

  3. If you have control over the SOAP server, simply make it output plain text which can be read as XML, instead of outputting actual XML. You can do that with Server.HTMLEncode over the data.

To get it to work for me, I had to change the dates from dd/mm/yyyy to yyyy/mm/dd

I would think there must be a better way, i.e. get an object or array (in a custom function?), but using simplexml_load_string returns

object(SimpleXMLElement)#6 (1) {
  ["Hotels"]=>
  array(3) {
    [0]=>
    object(SimpleXMLElement)#7 (6) {
      ["HotelID"]=>
      string(3) "253"
      ["RoomTypeID"]=>
      string(3) "101"
      ["RoomSerial"]=>
      string(1) "1"
      ["DateFrom"]=>
      string(25) "2010-04-12T00:00:00+02:00"
      ["DateTo"]=>
      string(25) "2010-04-13T00:00:00+02:00"
      ["Price"]=>
      string(6) "120.00"
    }
    [1]=>
    object(SimpleXMLElement)#8 (6) {
      ["HotelID"]=>
      string(3) "881"
      ["RoomTypeID"]=>
      string(3) "101"
      ["RoomSerial"]=>
      string(1) "1"
      ["DateFrom"]=>
      string(25) "2010-04-12T00:00:00+02:00"
      ["DateTo"]=>
      string(25) "2010-04-13T00:00:00+02:00"
      ["Price"]=>
      string(6) "290.00"
    }
    [2]=>
    object(SimpleXMLElement)#9 (6) {
      ["HotelID"]=>
      string(3) "881"
      ["RoomTypeID"]=>
      string(3) "102"
      ["RoomSerial"]=>
      string(1) "2"
      ["DateFrom"]=>
      string(25) "2010-04-12T00:00:00+02:00"
      ["DateTo"]=>
      string(25) "2010-04-13T00:00:00+02:00"
      ["Price"]=>
      string(6) "285.00"
    }
  }
}

i used the function [B]$xml = simplexml_load_string($result);

var_dump($xml);[/B]

but it returns an error

<br />
<b>Warning</b>:  simplexml_load_string() expects parameter 1 to be string, object given in <b>C:\\wamp\\www\\web_service\\working_2.php</b> on line <b>29</b><br />
NULL


Please tell me the right syntax of this function

thanks alot

The var_dump of $result showed me the “syntax” of the returned object.

So instead of loading the object I loaded the string using
$result->HotelsSearchResult->any

Like I said, it seems kind of odd. Getting an object, getting a string from it. passing that string (of XML) to a different object. But simplexml parses the string’s XML which seems better than writing my own parser to do it. It seems like getting the XML instead of an object with the XML in a string would be more efficient. But if that’s what you get to work with I guess that’s what you get to work with.

i wrote this code and it shows me the error… so what is the error in this code??

$xml = simplexml_load_string($result);

var_dump($xml);

You are passing the object - $result - to simplexml_load_string() instead of the string - $result->HotelsSearchResult->any

It might help if you think of how it would look if it was an array. i.e.

$result[‘HotelsSearchResult’][‘any’] = "<xml …

Except for objects (like simplexml) you use “->”