...

View Full Version : object IDs



NancyJ
05-02-2006, 03:44 PM
I'm using a php4 simplexml backport called ister simple xml to parse a complex xml document into objects. The problem I'm getting is echoing out the values I'm getting 'Object id #307' instead of the values.
Not sure what could be causing this problem.

fci
05-02-2006, 04:47 PM
try.. print_r or var_dump

NancyJ
05-02-2006, 04:49 PM
I used print_r and what it brought back was this:



IsterSimpleXMLElement Object ( [___t] => 2 [___l] => 9 [___ns] => 0 [___n] => Text [___a] => Array ( ) [___c] => Array ( [0] => IsterSimpleXMLElement Object ( [___t] => 3 [___l] => 10 [___ns] => [___n] => One bedroom apartment [___a] => Array ( ) [___c] => Array ( ) [loggers] => Array ( [IsterLoggerStd] => IsterLoggerStd Object ( [cgi] => 1 [loglevel] => 1792 ) ) [loglocal] => ) ) [loggers] => Array ( [IsterLoggerStd] => IsterLoggerStd Object ( [cgi] => 1 [loglevel] => 1792 ) ) [loglocal] => [ref] => IsterSimpleXMLElement Object *RECURSION* )

fci
05-02-2006, 05:23 PM
have you tried calling any of its methods like getChildren() or attributes? the ref is recursive because it calls addSimpleNode during instantiation.. you could try echo'ing/print_r'ing values from the class itself until you've got it debugged.

MRMAN
05-02-2006, 05:33 PM
so you happen to have a sample of the code that fills the array up.

NancyJ
05-02-2006, 06:04 PM
have you tried calling any of its methods like getChildren() or attributes? the ref is recursive because it calls addSimpleNode during instantiation.. you could try echo'ing/print_r'ing values from the class itself until you've got it debugged.
wow that was way over my head... how would i do that... I will post some code in a bit - on the phone to an dumb client atm lol.

This is the code that outputs the data


<?php require_once('inc/nusoap.php'); ?>
<?php require_once('inc/page.class.php'); ?>
<?$page = new accom();?>
<p class = "error"><?=$page->error?></p>|||

<? foreach($page->response as $offer)
{
if(($j % $page->perPage) == 0)
{
echo "|||";
?>
<table width="100%" cellspacing="1" cellpadding="1" class="paging">
<tr>
<td><img src="images/results_page_back.gif" width="24" height="14" alt = "previous"/><a href = "#" onclick="getPage(<?=floor($j/$page->perPage) <= 0 ? floor($j/$page->perPage) : floor($j/$page->perPage)-1 ?>)">PREVIOUS</a></td>
<td align="center"> Page <?=floor($j/$page->perPage)+1 ?> of <?=$page->pages?></td>
<td align="right"><a href = "#" onclick="getPage(<?=floor($j/$page->perPage)+1 >= $page->pages ? floor($j/$page->perPage) : floor($j/$page->perPage)+1 ?>)">NEXT<img src="images/results_page_forward.gif" width="24" height="14" alt ="next" /></a></td>
</tr>
</table>
<?
}
$j++;
?>

<table width="100%" cellspacing="1" cellpadding="1" class="tbltop">
<tr>
<td><?=$offer->Hotel->Name?></td>
<td align="right"><? for($i=0;$i<$offer->Hotel->Stars;$i++){?><img src="images/rating_sun.gif" width="16" height="15" alt = "star" /><?}?></td>
</tr>
</table>

<div class="row">
<table width="100%" cellspacing="1" cellpadding="1">
<tr valign="top">
<td align="center" width = "100"><a href = "moreinfo.php?h=<?=$offer->Hotel->Id?>" target = "_blank" ><img src="<?=$offer->Hotel->Photo->ThumbnailUrl?>" width="100" alt = "hotel thumbnail" /><br />more info</a></td>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<? $i=0;
foreach($offer->Result as $result){
$class=($i++ % 2) == 0 ? "grey": "white";?>
<tr>
<td class="<?=$class?>">
<table width="100%" cellspacing="1" cellpadding="1">
<tr valign="top">
<td style="text-align:left"><?= print_r($result->Room->RoomType->Text)." - ".$result->Room->MealType->Text?></td>
<td align="right"><b>&pound;<?=$result->Room->SellingPrice->Amount?></b><br /><img src="images/results_button_select.gif" width="57" height="23" alt = "select" /></td>
</tr>
</table>
</td>
</tr>

<?}?>
</table>
</td>
</tr>
</table>
</div>
<?
}
?>
|||

This is the code that creates the data

class accom
{
var $request;
var $error;
var $pages;
var $perPage =5;
var $response = array();
var $results = array();

function accom()
{
set_time_limit(300);
$sql = "SELECT fldRegionID FROM tblDestinations WHERE fldAPC like '%".stripslashes($_GET['a29'])."%'";
$result = mysql_query($sql);
$region = mysql_result($result, 0);

//get data from flight
$uid = "{".$_GET['uid']."}";

$message ='<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<AvailabilitySearch xmlns="url">
<xiRequest>
<HotelStayDetails>
<ArrivalDate>'.$_GET['a8'].'</ArrivalDate>
<Nights>'.$_GET['a32'].'</Nights>
<Room>
<MealType>'.$_GET['b'].'</MealType>
<Guests>';
for($i=0;$i<$_GET['a'];$i++)
{
$message.="<Adult/>";
}
for($i=0;$i<$_GET['c'];$i++)
{
$message.="<Child>
<Age>11</Age>
</Child>";
}
for($i=0;$i<$_GET['i'];$i++)
{
$message.="<Child>
<Age>1</Age>
</Child>";
}
$message.='</Guests>
</Room>
</HotelStayDetails>
<HotelSearchCriteria>
<MinStars>'.$_GET['r'].'</MinStars>
</HotelSearchCriteria>
<RegionId>'.$region.'</RegionId>
<DetailLevel>summary</DetailLevel>
</xiRequest>
</AvailabilitySearch>
</soap:Body>
</soap:Envelope>';
//echo $message;
$soapclient = new nuSoapclient('url');

$soapclient->send($message, "url");

$xmlString = str_replace("soap:Body", "soapBody",$soapclient->response);
$xmlString = str_replace("soap:Envelope", "soapEnvelope",$xmlString);
//echo $xmlString;
$xmlString = stristr($xmlString, "<?xml");

//$response = simplexml_load_string($xmlString);
//echo $xmlString;
require_once('class/IsterXmlSimpleXMLImpl.php');
$impl = new IsterXmlSimpleXMLImpl;
if(!empty($xmlString))
{
$response = $impl->load_string($xmlString);
$this->response = $response->soapEnvelope->soapBody->AvailabilitySearchResponse->AvailabilitySearchResult->HotelAvailability;
$this->pages = ceil(count($this->response)/$this->perPage);

}

//echo "Results :".count($this->response);
if(empty($xmlString))
{
$this->error = "Sorry, our accomodation search is currently unavailable or too busy to answer your request. Please wait a few minutes and <a href = \"javascript:window.location.reload();\">click here to refresh this page.</a>";
$this->response = array();
}
elseif(count($this->response)==0)
{
$this->error = "Sorry, there were no accomodation results matching your request, please <a href = \"flightsx.php?{$_SERVER['argv'][0]}\">click here to choose a different flight</a>";
$this->response = array();
// echo $xmlString;
//echo $message;
}
}
}

This is an example of what gets sent back -


<?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><AvailabilitySearchResponse xmlns="http://www.reservwire.com/namespace/WebServices/Xml">
<AvailabilitySearchResult>
<HotelAvailability>
<Hotel>
<Id>88302761</Id>
<Name>Hotel Sur Beach</Name>
<Region>
<Id>80055107</Id>
<Name>Cala Bona</Name>
</Region>
<Type>Hotel</Type>
<Address>
<Address1>PASEO MARITIMO, 25</Address1>
<Address2>CALA BONA</Address2>
<City>MALLORCA</City>
<Zip>07559</Zip>
<Country>SPAIN</Country>
<Tel>0034 971 585 190</Tel>
<Fax>0034 971 813 501</Fax>
<Email>pagobeach@telefonica.net</Email>
</Address>
<Stars>2</Stars>
<GeneralInfo />
<Photo>
<Url>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20pool.jpg</Url>
<Width>600</Width>
<Height>411</Height>
<Bytes>46248</Bytes>
<ThumbnailUrl>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20pool_thumb.jpg</ThumbnailUrl>
<ThumbnailWidth>102</ThumbnailWidth>
<ThumbnailHeight>70</ThumbnailHeight>
<ThumbnailBytes>2764</ThumbnailBytes>
</Photo>
<Photo>
<Url>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_CBona%20beach.jpg</Url>
<Width>405</Width>
<Height>480</Height>
<Bytes>117945</Bytes>
<ThumbnailUrl>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_CBona%20beach_thumb.jpg</ThumbnailUrl>
<ThumbnailWidth>59</ThumbnailWidth>
<ThumbnailHeight>70</ThumbnailHeight>
<ThumbnailBytes>1643</ThumbnailBytes>
</Photo>
<Photo>
<Url>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_CBona%20air.jpg</Url>
<Width>544</Width>
<Height>508</Height>
<Bytes>250419</Bytes>
<ThumbnailUrl>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_CBona%20air_thumb.jpg</ThumbnailUrl>
<ThumbnailWidth>74</ThumbnailWidth>
<ThumbnailHeight>70</ThumbnailHeight>
<ThumbnailBytes>2094</ThumbnailBytes>
</Photo>
<Photo>
<Url>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20Pagopago.jpg</Url>
<Width>600</Width>
<Height>449</Height>
<Bytes>47487</Bytes>
<ThumbnailUrl>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20Pagopago_thumb.jpg</ThumbnailUrl>
<ThumbnailWidth>93</ThumbnailWidth>
<ThumbnailHeight>70</ThumbnailHeight>
<ThumbnailBytes>2609</ThumbnailBytes>
</Photo>
<Photo>
<Url>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20room.jpg</Url>
<Width>600</Width>
<Height>413</Height>
<Bytes>41841</Bytes>
<ThumbnailUrl>http://test.holidaybrokers.co.uk/OHGImages/Hotel/88302761_Sur%20room_thumb.jpg</ThumbnailUrl>
<ThumbnailWidth>101</ThumbnailWidth>
<ThumbnailHeight>70</ThumbnailHeight>
<ThumbnailBytes>2604</ThumbnailBytes>
</Photo>
<Description>
<Type>Summary-Features</Type>
<Text>The rooms are either twins, or larger rooms for up to four adults. There is a swimming pool with a seperate childrens section and terrace with sunbeds. You can either have just bed and breakfast, or take the half board option. The Hotel Sur Beach also has the fantastic Pago Pago bar where there is always something going on! </Text>
</Description>
<Description>
<Type>Summary-Property</Type>
<Text>The Hotel Sur Beach offers all that you need for a lively holiday in the lovely, friendly, resort of Cala Bona! The newly refurbished hotel is situated in the centre of the resort, just 100m from the sandy beach in one direction and 200m from the picturesque harbour in the other direction. The Sur Beach is perfect for families or couples wanting a fun, lively holiday. There is live music most evenings and it is proving to be THE PLACE to be in Cala Bona!!! This is an excellent value hotel for couples, groups or families looking for a fun, lively holiday in the eternally popular resort of Cala Bona.</Text>
</Description>
</Hotel>
<Result>
<QuoteId>7214038-0</QuoteId>
<Room>
<RoomType>
<Code>1004905</Code>
<Text>Twin </Text>
</RoomType>
<MealType>
<Code>1</Code>
<Text>B &amp; B</Text>
</MealType>
<SellingPrice>
<Currency>GBP</Currency>
<Amount>267.54</Amount>
<Estimated>false</Estimated>
<Converted>false</Converted>
</SellingPrice>
</Room>
</Result>
</HotelAvailability>
</AvailabilitySearchResult>
</AvailabilitySearchResponse>
</soap:Body>
</soap:Envelope>

fci
05-02-2006, 09:42 PM
I currently don't have the time to go that in-depth and figure it out... sorry.. I woudl suggest reading the source code of the XML classes and seeing what methods you can use ..

NancyJ
05-03-2006, 11:49 AM
Just for reference, sorted it. Missread something in the documentation - to echo out the contents of a node you ahve to use CDATA();
eg. $root->node->CDATA();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum