Does everything really need to be done in functions? I have two feeds I need to parse into one page. One is a list of hotels, and from that, I need to get the hotel details.
http://www.travelyucatan.com/get_xml.php?t=hl&dest=12&order_by=1&ascdesc=asc would be the list of hotels.
>> returns something like this :
<?xml version="1.0" encoding="utf-8"?>
<Response Version="1.0">
<Request_Id>TVLYUC1202787716</Request_Id>
<Language>ING</Language>
<Currency>US</Currency>
<Timestamp>2/11/2008 10:41:56 PM</Timestamp>
<Hotel>
<Hotel_Id>565</Hotel_Id>
<Hotel_Name>Casa Iguana Hotel</Hotel_Name>
<Status>AV</Status>
<Category>4E</Category>
<Location_Id>VILL</Location_Id>
<Location_Name>Village</Location_Name>
<LowestRate>32.10</LowestRate>
<Destination_Id>12</Destination_Id>
<Destination_Name>Puerto Vallarta</Destination_Name>
<City_Id>PTRM</City_Id>
<City_Name>Mismaloya</City_Name>
<IsPromo>YES</IsPromo>
<isNightFree>YES</isNightFree>
<NightFree>3</NightFree>
<isLastMinute>NO</isLastMinute>
</Hotel>
<Hotel>
<Hotel_Id>389</Hotel_Id>
<Hotel_Name>Costa Club Punta Arena All Inclusive</Hotel_Name>
<Status>AV</Status>
<Category>4E</Category>
<Location_Id>PLAY</Location_Id>
<Location_Name>Beach</Location_Name>
<LowestRate>62.67</LowestRate>
<Destination_Id>12</Destination_Id>
<Destination_Name>Puerto Vallarta</Destination_Name>
<City_Id>PTR</City_Id>
<City_Name>Vallarta Hotel Zone</City_Name>
<IsPromo>NO</IsPromo>
<isNightFree>NO</isNightFree>
<NightFree>0</NightFree>
<isLastMinute>NO</isLastMinute>
</Hotel>
<Hotel>
<Hotel_Id>459</Hotel_Id>
<Hotel_Name>El Pescador</Hotel_Name>
<Status>AV</Status>
<Category>3E</Category>
<Location_Id>PLAY</Location_Id>
<Location_Name>Beach</Location_Name>
<LowestRate>36.67</LowestRate>
<Destination_Id>12</Destination_Id>
<Destination_Name>Puerto Vallarta</Destination_Name>
<City_Id>PTRN</City_Id>
<City_Name>Downtown Vallarta</City_Name>
<IsPromo>YES</IsPromo>
<isNightFree>NO</isNightFree>
<NightFree>0</NightFree>
<isLastMinute>NO</isLastMinute>
</Hotel>
<MACHINE>IPDMCZ0360MIA</MACHINE>
</Response>
and the details, let's take the first one as an example is
<?xml version="1.0" encoding="utf-8"?>
<Response Version="1.0">
<Request_Id>TVLYUC1202787890</Request_Id>
<Timestamp>2008-02-11T22:44:50</Timestamp>
<Product>Hotel</Product>
<Language>ING</Language>
<Currency>US</Currency>
<Hotel_Id>565</Hotel_Id>
<Hotel_Name>Casa Iguana Hotel</Hotel_Name>
<Category>4E</Category>
<Location_Id>VILL</Location_Id>
<Location_Name>Village</Location_Name>
<Destination_Id>12</Destination_Id>
<Destination_Name>Puerto Vallarta</Destination_Name>
<City_Id>PTRM</City_Id>
<City_Name>Mismaloya</City_Name>
<General_Description>If you are coming to Puerto Vallarta, you can't miss the little picturesque village of Mismaloya, with all the adventure, tranquility and natural beauty of Mexico. The Casa Iguana Hotel has a garden setting with all the amenities and excelent service. Casa Iguana is surrounded by mountains and is the perfect choice for unwinding.</General_Description>
<Location_Description>Casa Iguana Hotel is a five minute walk from the Mismaloya beach. It is located between the reknown Banderas Bay and Puerto Vallarta's jungle. At 15 minutes from de center of Puerto Vallarta.</Location_Description>
<Hotel_Status>AV</Hotel_Status>
<Age_Min>0</Age_Min>
<Gallery>
<Front_View>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/fachada.jpg</Front_View>
<Picture>
<Name>Two bedroom suite</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/suite.jpg</filename>
</Picture>
<Picture>
<Name>Internet</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/center.jpg</filename>
</Picture>
<Picture>
<Name>Garden</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/garden.jpg</filename>
</Picture>
<Picture>
<Name>Jacuzzi</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/jac.jpg</filename>
</Picture>
<Picture>
<Name>Lobby</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/lobby.jpg</filename>
</Picture>
<Picture>
<Name>Pool</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/pool.jpg</filename>
</Picture>
<Picture>
<Name>Bridge</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/puente.jpg</filename>
</Picture>
<Picture>
<Name>River</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/river.jpg</filename>
</Picture>
<Picture>
<Name>Gift Shop</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/tienda.jpg</filename>
</Picture>
<Picture>
<Name>La Palapa Bar</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/bar.jpg</filename>
</Picture>
<Picture>
<Name>La Cocina Restaurant</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Puerto_Vallarta/Hotels/Casa_Iguana_Hotel/gallery/rest.jpg</filename>
</Picture>
</Gallery>
<Services>
<Service>
<Name>Internet</Name>
<Description>During your vacation you will be able to keep in touch with your family and friends, since our beautiful hotel provides you computers with internet connection for your comfort.</Description>
</Service>
<Service>
<Name>Pool (s)</Name>
<Description>Delight on this delicious open-air pool, admire the landscape and take a nap on the lounge chairs around it.</Description>
</Service>
<Service>
<Name>Gift Shop (s)</Name>
<Description>A gift shop is located on the premises for your convenience. Here you can find all kinds of souvenirs that will remind you back home of your wonderful stay.</Description>
</Service>
<Service>
<Name>Jacuzzi</Name>
<Description>You will spend a very relaxing moments in side of our jacuzzi delighting your favorite drink with your loved one.</Description>
</Service>
<Service>
<Name>Massages</Name>
<Description>To complete the scene, give yourself into deep relax with a massage by expert hands, the antidote for stress.</Description>
</Service>
<Service>
<Name>Restaurant (s)</Name>
<Description />
</Service>
<Service>
<Name>Doctor</Name>
<Description>Medical service available. Ask in the front desk.</Description>
</Service>
<Service>
<Name>Bar (s)</Name>
<Description />
</Service>
<Service>
<Name>Car Rental</Name>
<Description>If you have planned to explore the surroundings, in the hotel you will find a car rental agency that will surely offer you a good plan.</Description>
</Service>
<Service>
<Name>Conference Room (s)</Name>
<Description />
</Service>
<Service>
<Name>Babysitter</Name>
<Description>Qualified babysitting services are available. Advance notice required.</Description>
</Service>
<Service>
<Name>Safe Deposit Box</Name>
<Description>At the reception there are safe deposit boxes where your valuable belongings will be completely safe.</Description>
</Service>
<Service>
<Name>Money Exchange</Name>
<Description>For your comfort you will find an exchange office at the hotel.</Description>
</Service>
<Service>
<Name>Laundry</Name>
<Description>Quick and efficient laundry service available.</Description>
</Service>
</Services>
<Restaurants_Bars>
<Restaurant>
<Rest_Name>La Cocina</Rest_Name>
<Rest_Description>Nice decorated restaurant, with a beautiful view to the garden. There you can eat an exquisite dish of Mexican or International cuisine.</Rest_Description>
</Restaurant>
<Bar>
<Bar_Name>La Palapa</Bar_Name>
<Bar_Description>Enjoy a glass of your favorite wine or cocktail, inside La Cocina restaurant.</Bar_Description>
</Bar>
</Restaurants_Bars>
<Rooms>
<Consulta>spw_search_hoteles_cuartos_planes_tarifas @Clav_Idioma = 'ING',@Clav_Mercado = 'INTER',@Clav_Hotel = 565</Consulta>
<Room type_Id="2BDRSTE" meal_plan="ZZ">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Two-bedroom suite</Room_Name>
<Meal_plan_Name>Room Only</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>2</Max_Kids>
<Max_Extras>2</Max_Extras>
<Max_Capacity>4</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>12</Age_Max_Kids>
<Age_Min_Junior>0</Age_Min_Junior>
<Age_Max_Junior>0</Age_Max_Junior>
<Rate from="12/20/2007" to="3/23/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>75.1111</Single_Pub>
<Double_Pub>37.5556</Double_Pub>
<Triple_Pub>75.1111</Triple_Pub>
<Quad_Pub>75.1111</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="3/24/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>72.2222</Single_Pub>
<Double_Pub>36.1111</Double_Pub>
<Triple_Pub>72.2222</Triple_Pub>
<Quad_Pub>72.2222</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="7/1/2008" to="8/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>85.2222</Single_Pub>
<Double_Pub>42.6111</Double_Pub>
<Triple_Pub>85.2222</Triple_Pub>
<Quad_Pub>85.2222</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="8/16/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>75.1111</Single_Pub>
<Double_Pub>37.5556</Double_Pub>
<Triple_Pub>75.1111</Triple_Pub>
<Quad_Pub>75.1111</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Promo code="0004" FROM="1/12/2008" to="3/23/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>75.1111</Single_Pub>
<Double_Pub>37.5556</Double_Pub>
<Triple_Pub>75.1111</Triple_Pub>
<Quad_Pub>75.1111</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
<Nights_Free>Yes</Nights_Free>
<Num_Night>3</Num_Night>
</Promo>
</Room>
</Rooms>
</Response>
I am trying to parse these two feeds into one. All i need from the First is the list of IDs, Hotel name and lowest rate.
From the second I need quite a bit of the information such as a list of their Room->Meal_Plans and such,
Any help would be greatly appreciated.
Please let me know if you need more information.
Thanks
Chad
I do appreciate the response and it has helped me a bit. i do have the record handler going into an XML value. The problem now is that i cannot extract the attribute for Meal Plan, which if I understand should be $record["ROOM-MEAL_PLAN"].
Please help.
<?php
function myRoomPlans($record) {
$mp = array();
$mp[] = $record;
foreach ($mp as $meal) {
print "<a href='' title='What is a ".$meal_options[$mp["ROOM-MEAL_PLAN"]]."'><img src='".$meal_optn_lrg[$mp["ROOM-MEAL_PLAN"]]."' alt='".$meal_options[$mp["ROOM-MEAL_PLAN"]]."' border=0 /></a> ";
}
}
$url = "http://www.travelyucatan.com/get_xml.php?t=hd&h_id=".$h_id->value;
$fp = fopen($url,"r");
$hot_data = "";
while(!feof($fp)) $hot_data .= fread($fp,1024);
fclose($fp);
?>
<?php
MagicParser_parse("string://".$hot_data,"myRoomPlans","xml|RESPONSE/ROOMS/");
?>
I am using a combination of your script and a free one. that's where the $h_id->value comes from.
Hi Chad,
You do have the key correct "ROOM-MEAL_PLAN", however looking at your code I think you meant to use $meal instead of $mp; so rather than:
$meal_options[$mp["ROOM-MEAL_PLAN"]]
try:
$meal_options[$meal["ROOM-MEAL_PLAN"]]
However, before that would work, you will also need to declare $meal_options as global within the myRecordHandler function, otherwise the value will be empty as it is considered a local variable:
function myRoomPlans($record) {
global $meal_options;
...
Hope this helps!
Cheers,
David.
We're almost there. Now I only have one, which is a good start, I need the other plans for the other rooms too. The output is only giving me the first meal plan for the first room.
There are a bunch of attributes, but each of the Room has with the XX being something unique to each.
Any ideas?
Hi Chad,
In the example XML above there is only one room with one meal plan (I think). Can you post a snipped of a room XML where there is more than one meal plan?
Cheers,
David.
<?xml version="1.0" encoding="utf-8"?>
<Response Version="1.0">
<Request_Id>TVLYUC1202843821</Request_Id>
<Timestamp>2008-02-12T14:17:01</Timestamp>
<Product>Hotel</Product>
<Language>ING</Language>
<Currency>US</Currency>
<Hotel_Id>1220</Hotel_Id>
<Hotel_Name>Casa Las Tortugas</Hotel_Name>
<Category>3C</Category>
<Location_Id>PLAY</Location_Id>
<Location_Name>Beach</Location_Name>
<Destination_Id>14</Destination_Id>
<Destination_Name>Holbox</Destination_Name>
<City_Id>HOLBX</City_Id>
<City_Name>Isla Holbox</City_Name>
<General_Description>For those ones who like to be in contact with nature and look for a pacific place to go on vacation, Greta and Francesca look forward to welcoming you with genuine Italian warmth, giving you a personalized family-like service in this beautiful place called Casa Las Tortugas.<br><br>In this lovely ecological hotel located on the beach, you will find great comfort enjoying the splendid natural setting and admiring the amazing flora and fauna of this wonderful ocean that surrounds this island of dreams and adventures.</General_Description>
<Location_Description>Surrounded by tropical mangroves and lush garden grow is situated Casa Las Tortugas, in Playa Blanca, at 99 miles from the Cancun International Airport, approximately 2 hour and 30 minutes away. In the natural Biosphere reserve of Yum Balam, in the beautiful Holbox Island, you will have the opportunity to be in contact with the predominant flora and fauna.</Location_Description>
<Hotel_Status>AV</Hotel_Status>
<Age_Min>0</Age_Min>
<Gallery>
<Front_View>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/fachada.jpg</Front_View>
<Picture>
<Name>Bungalow Tucano</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/bungalow_tucano.jpg</filename>
</Picture>
<Picture>
<Name>Junior</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/junior.jpg</filename>
</Picture>
<Picture>
<Name>Standard Room</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/standard.jpg</filename>
</Picture>
<Picture>
<Name>Suite</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/suite.jpg</filename>
</Picture>
<Picture>
<Name>Matrimonial Room</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/Triple.jpg</filename>
</Picture>
<Picture>
<Name>Facilities</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/descanso.jpg</filename>
</Picture>
<Picture>
<Name>Facilities</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/instalaciones.jpg</filename>
</Picture>
<Picture>
<Name>Palapas</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/palapas.jpg</filename>
</Picture>
<Picture>
<Name>Water Sport Activities</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/actividades.jpg</filename>
</Picture>
<Picture>
<Name>Beach</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/playa.jpg</filename>
</Picture>
<Picture>
<Name>Café del Mar Restaurant</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/restaurant.jpg</filename>
</Picture>
<Picture>
<Name>Café del Mar Restaurant</Name>
<filename>https://www.e-travelsolution.com/_lib/vimages/Holbox/Hotels/Casa_Las_Tortugas/gallery/restaurant-2.jpg</filename>
</Picture>
</Gallery>
<Services>
<Service>
<Name>Water Activities</Name>
<Description>A great variety of water sports is available at the hotel, including kiteboarding and kite surf lessons.</Description>
</Service>
<Service>
<Name>Beach</Name>
<Description>Relax on the sand topping up your tan in the Caribbean or if you prefer, enjoy an array of water sports on the beautiful and calm beach.</Description>
</Service>
<Service>
<Name>Fishing</Name>
<Description />
</Service>
<Service>
<Name>Massages</Name>
<Description>To complete the scene, indulge yourself into deep relaxation with a massage provided by expert hands, the perfect relief for stress.</Description>
</Service>
<Service>
<Name>Special Features</Name>
<Description>We have a team of highly qualified tour guides, the appropriate snorkel gear and everything you need to know about the whale shark. In this tour we will also provide you a succulent lunch. Don’t miss this opportunity!
<br><br>For the comfort and tranquility of our guests, at Casa Las Tortugas we take credit cards.</Description>
</Service>
<Service>
<Name>Volleyball</Name>
<Description />
</Service>
<Service>
<Name>Wireless Internet</Name>
<Description />
</Service>
<Service>
<Name>Restaurant (s)</Name>
<Description />
</Service>
<Service>
<Name>Sailing</Name>
<Description />
</Service>
<Service>
<Name>Wedding Facilities</Name>
<Description>We designed several packages that could fit your expectations or we can help you design your own package in this land of turquoise waters, coral reefs and white-sand beaches that offers the honeymooner activities galore.</Description>
</Service>
<Service>
<Name>Babysitter</Name>
<Description>Qualified babysitting services are available. Advance notice required.</Description>
</Service>
<Service>
<Name>Handicapped Facilities</Name>
<Description>The hotel has areas specifically designed to meet the special needs of disabled guests. Please request at time of reservation.</Description>
</Service>
<Service>
<Name>Safe Deposit Box</Name>
<Description>At the reception there are safe deposit boxes where your valuable belongings will be completely safe.</Description>
</Service>
<Service>
<Name>Transportation Available</Name>
<Description>We offer Airport transfer service with extra-charge.</Description>
</Service>
<Service>
<Name>Kayak</Name>
<Description />
</Service>
<Service>
<Name>Laundry</Name>
<Description>Quick and efficient laundry service available.</Description>
</Service>
<Service>
<Name>Room Service</Name>
<Description />
</Service>
</Services>
<Restaurants_Bars>
<Restaurant>
<Rest_Name>Café del Mar</Rest_Name>
<Rest_Description>Cooked with an unbeatable seasoning, we have exquisite dishes of Mediterranean fare that will fascinate you, as well as delicious fresh seafood dishes.</Rest_Description>
</Restaurant>
</Restaurants_Bars>
<Rooms>
<Consulta>spw_search_hoteles_cuartos_planes_tarifas @Clav_Idioma = 'ING',@Clav_Mercado = 'INTER',@Clav_Hotel = 1220</Consulta>
<Room type_Id="BGW" meal_plan="CP">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Bungalow</Room_Name>
<Meal_plan_Name>Continental Breakfast Included</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>1</Max_Kids>
<Max_Extras>1</Max_Extras>
<Max_Capacity>3</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>5</Age_Max_Kids>
<Age_Min_Junior>6</Age_Min_Junior>
<Age_Max_Junior>12</Age_Max_Junior>
<Rate from="1/9/2008" to="3/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>122.9268</Single_Pub>
<Double_Pub>61.4634</Double_Pub>
<Triple_Pub>122.9268</Triple_Pub>
<Quad_Pub>122.9268</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="3/16/2008" to="3/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>157.0732</Single_Pub>
<Double_Pub>78.5366</Double_Pub>
<Triple_Pub>157.0732</Triple_Pub>
<Quad_Pub>157.0732</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="4/1/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>122.9268</Single_Pub>
<Double_Pub>61.4634</Double_Pub>
<Triple_Pub>122.9268</Triple_Pub>
<Quad_Pub>122.9268</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="7/1/2008" to="8/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>146.1463</Single_Pub>
<Double_Pub>73.0732</Double_Pub>
<Triple_Pub>146.1463</Triple_Pub>
<Quad_Pub>146.1463</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="9/1/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>122.9268</Single_Pub>
<Double_Pub>61.4634</Double_Pub>
<Triple_Pub>122.9268</Triple_Pub>
<Quad_Pub>122.9268</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="12/20/2008" to="1/7/2009">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>157.0732</Single_Pub>
<Double_Pub>78.5366</Double_Pub>
<Triple_Pub>157.0732</Triple_Pub>
<Quad_Pub>157.0732</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
</Room>
<Room type_Id="BGWF" meal_plan="CP">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Bungalow Familiar</Room_Name>
<Meal_plan_Name>Continental Breakfast Included</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>1</Max_Kids>
<Max_Extras>2</Max_Extras>
<Max_Capacity>4</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>5</Age_Max_Kids>
<Age_Min_Junior>6</Age_Min_Junior>
<Age_Max_Junior>12</Age_Max_Junior>
<Rate from="1/9/2008" to="3/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>207.6098</Single_Pub>
<Double_Pub>103.8049</Double_Pub>
<Triple_Pub>207.6098</Triple_Pub>
<Quad_Pub>207.6098</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="3/16/2008" to="3/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>252.6829</Single_Pub>
<Double_Pub>126.3415</Double_Pub>
<Triple_Pub>252.6829</Triple_Pub>
<Quad_Pub>252.6829</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="4/1/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>207.6098</Single_Pub>
<Double_Pub>103.8049</Double_Pub>
<Triple_Pub>207.6098</Triple_Pub>
<Quad_Pub>207.6098</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="7/1/2008" to="8/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>241.7561</Single_Pub>
<Double_Pub>120.8780</Double_Pub>
<Triple_Pub>241.7561</Triple_Pub>
<Quad_Pub>241.7561</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="9/1/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>207.6098</Single_Pub>
<Double_Pub>103.8049</Double_Pub>
<Triple_Pub>207.6098</Triple_Pub>
<Quad_Pub>207.6098</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="12/20/2008" to="1/7/2009">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>252.6829</Single_Pub>
<Double_Pub>126.3415</Double_Pub>
<Triple_Pub>252.6829</Triple_Pub>
<Quad_Pub>252.6829</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
</Room>
<Room type_Id="JR" meal_plan="CP">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Junior</Room_Name>
<Meal_plan_Name>Continental Breakfast Included</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>1</Max_Kids>
<Max_Extras>2</Max_Extras>
<Max_Capacity>4</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>5</Age_Max_Kids>
<Age_Min_Junior>6</Age_Min_Junior>
<Age_Max_Junior>12</Age_Max_Junior>
<Rate from="1/8/2008" to="3/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>106.5366</Single_Pub>
<Double_Pub>53.2683</Double_Pub>
<Triple_Pub>106.5366</Triple_Pub>
<Quad_Pub>106.5366</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="3/16/2008" to="3/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>129.7561</Single_Pub>
<Double_Pub>64.8780</Double_Pub>
<Triple_Pub>129.7561</Triple_Pub>
<Quad_Pub>129.7561</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="4/1/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>106.5366</Single_Pub>
<Double_Pub>53.2683</Double_Pub>
<Triple_Pub>106.5366</Triple_Pub>
<Quad_Pub>106.5366</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="9/1/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>106.5366</Single_Pub>
<Double_Pub>53.2683</Double_Pub>
<Triple_Pub>106.5366</Triple_Pub>
<Quad_Pub>106.5366</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="12/20/2008" to="1/7/2009">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>129.7561</Single_Pub>
<Double_Pub>64.8780</Double_Pub>
<Triple_Pub>129.7561</Triple_Pub>
<Quad_Pub>129.7561</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
</Room>
<Room type_Id="ST" meal_plan="CP">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Suite</Room_Name>
<Meal_plan_Name>Continental Breakfast Included</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>0</Max_Kids>
<Max_Extras>0</Max_Extras>
<Max_Capacity>2</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>5</Age_Max_Kids>
<Age_Min_Junior>6</Age_Min_Junior>
<Age_Max_Junior>12</Age_Max_Junior>
<Rate from="1/8/2008" to="3/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>101.0732</Single_Pub>
<Double_Pub>50.5366</Double_Pub>
<Triple_Pub>101.0732</Triple_Pub>
<Quad_Pub>101.0732</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="3/16/2008" to="3/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>122.9268</Single_Pub>
<Double_Pub>61.4634</Double_Pub>
<Triple_Pub>122.9268</Triple_Pub>
<Quad_Pub>122.9268</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="4/1/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>101.0732</Single_Pub>
<Double_Pub>50.5366</Double_Pub>
<Triple_Pub>101.0732</Triple_Pub>
<Quad_Pub>101.0732</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="7/1/2008" to="8/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>112.0000</Single_Pub>
<Double_Pub>56.0000</Double_Pub>
<Triple_Pub>112.0000</Triple_Pub>
<Quad_Pub>112.0000</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="9/1/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>101.0732</Single_Pub>
<Double_Pub>50.5366</Double_Pub>
<Triple_Pub>101.0732</Triple_Pub>
<Quad_Pub>101.0732</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
<Rate from="12/20/2008" to="1/7/2009">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>122.9268</Single_Pub>
<Double_Pub>61.4634</Double_Pub>
<Triple_Pub>122.9268</Triple_Pub>
<Quad_Pub>122.9268</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>0</Junior_Pub>
</Rate>
</Room>
<Room type_Id="TPL" meal_plan="CP">
<Hotel_Room_Status>AV</Hotel_Room_Status>
<Room_Name>Matrimonial</Room_Name>
<Meal_plan_Name>Continental Breakfast Included</Meal_plan_Name>
<Max_Adults>2</Max_Adults>
<Max_Kids>1</Max_Kids>
<Max_Extras>1</Max_Extras>
<Max_Capacity>3</Max_Capacity>
<Max_Bedding>0</Max_Bedding>
<Age_Min_Kids>0</Age_Min_Kids>
<Age_Max_Kids>5</Age_Max_Kids>
<Age_Min_Junior>6</Age_Min_Junior>
<Age_Max_Junior>12</Age_Max_Junior>
<Rate from="1/9/2008" to="3/15/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>84.6829</Single_Pub>
<Double_Pub>42.3415</Double_Pub>
<Triple_Pub>84.6829</Triple_Pub>
<Quad_Pub>84.6829</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="3/16/2008" to="3/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>106.5366</Single_Pub>
<Double_Pub>53.2683</Double_Pub>
<Triple_Pub>106.5366</Triple_Pub>
<Quad_Pub>106.5366</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="4/1/2008" to="6/30/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>84.6829</Single_Pub>
<Double_Pub>42.3415</Double_Pub>
<Triple_Pub>84.6829</Triple_Pub>
<Quad_Pub>84.6829</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="7/1/2008" to="8/31/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>95.6098</Single_Pub>
<Double_Pub>47.8049</Double_Pub>
<Triple_Pub>95.6098</Triple_Pub>
<Quad_Pub>95.6098</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
<Rate from="9/1/2008" to="12/19/2008">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>84.6829</Single_Pub>
<Double_Pub>42.3415</Double_Pub>
<Triple_Pub>84.6829</Triple_Pub>
<Quad_Pub>84.6829</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>13.6585</Junior_Pub>
</Rate>
<Rate from="12/20/2008" to="1/7/2009">
<Cutt>0</Cutt>
<Single_Net>0</Single_Net>
<Double_Net>0</Double_Net>
<Triple_Net>0</Triple_Net>
<Quad_Net>0</Quad_Net>
<Kids_Net>0</Kids_Net>
<Junior_Net>0</Junior_Net>
<Single_Pub>106.5366</Single_Pub>
<Double_Pub>53.2683</Double_Pub>
<Triple_Pub>106.5366</Triple_Pub>
<Quad_Pub>106.5366</Quad_Pub>
<Kids_Pub>0</Kids_Pub>
<Junior_Pub>20.4878</Junior_Pub>
</Rate>
</Room>
</Rooms>
</Response>
Here it is with more than one room and more than one meal plan.
Thanks, Chad.
Of the multiple ROOM records; what indicates the same room with a different plan?
Each record has:
<Room type_Id="BGW" meal_plan="CP">
...but I don't see any where type_Id is the same with a different meal_plan...
If there were, is this how it would be represented; eg:
<Room type_Id="BGW" meal_plan="CP1">
...
</Room>
<code>
<Room type_Id="BGW" meal_plan="CP2">
...
</Room>
Cheers,
David.
I don't even care about the type_id's right now, just the meal plans. I need a list of meal plans for each hotel based on the Hotel ID.
Hi Chad,
I'm with you.
This can be sorted by using a lower level format string. It was working before because there was only one room. Instead of:
xml|RESPONSE/ROOMS/
...use:
xml|RESPONSE/ROOMS/ROOM/
...for example:
<?php
MagicParser_parse("string://".$hot_data,"myRoomPlans","xml|RESPONSE/ROOMS/ROOM/");
?>
That should be the only change you need to make the key will be the same...
Cheers,
David.
Does this parser return arrays or loops already? I ask because this code :
<?php
function myRoomPlans($record) {
global $meal_options;
global $meal_optn_lrg;
$mp = array();
$shown = array();
$mp[] = $record;
for ($x=0; $x<count($mp); $x++) {
$words = $meal_options[$mp[$x]["ROOM-MEAL_PLAN"]];
$img = $meal_optn_lrg[$mp[$x]["ROOM-MEAL_PLAN"]];
if (!in_array($words,$shown)) {
print "<a href=\"javascript:reqWin('hotels/plans.php')\" title=\"What is a ".$words."\"><img src='".$img."' alt='".$words."' border=0 /></a> ";
$shown[$x] = $words;
}
}
print_r($shown);
}
?>
Returns :
Room with Meal Plans Array ( [0] => Room with Meal Plans )
Room with Meal Plans Array ( [0] => Room with Meal Plans )
Hi Chad,
$record is a flat, associative array with each field.
The reason your code works is because you are adding this to another array, and then looping through that array; however there will only ever be one value your new arrary, so it's actually unnecessary.
You can simply access $record["ROOM-MEAL_PLAN"] for example within the record handler function.
The record handler function will be called once for every record in the XML.
Cheers,
David.
I think I am missing something that is blatantly obvious ... if they already come out in an associative array, how do I use the values in a foreach loop? All this does is print out the values.
Hi Chad,
The record handler function is called multiple times, once for every record in the feed - that's how it works.
Have a look at the following BBC News Headlines example. You will see how within the record handler function you are only printing one item, but when you run the script you will see how every record in the RSS feed is displayed...
http://www.magicparser.com/node/26
Cheers,
David.
Hello Chad,
Ultimately, Magic Parser is not ideally suited to the second type of XML (the hotel information) as it contains different "types" of repeating records - services, images, rooms, and then within each room you have rates and promos. Magic Parser is designed to extract into a single, flat array, each record of an XML feed that has multiple records that you need to process individually.
For example, in your first file, it is a list of HOTEL records; so you would use Magic Parser with the format string:
xml|RESPONSE/HOTEL/
Here's an example that just extracts each hotel id, name and lowestrate into a global array, which you can use late:
View Output
<?php
// use text/plain output for clarity, saves having to generate HTML
header("Content-Type: text/plain");
require("MagicParser.php");
$hotels = array();
function myRecordHandler($record)
{
// create an array of the hotel information we want
$hotel = array();
$hotel["ID"] = $record["HOTEL_ID"];
$hotel["NAME"] = $record["HOTEL_NAME"];
$hotel["LOWESTRATE"] = $record["LOWESTRATE"];
// add this hotel to the global array
global $hotels;
$hotels[] = $hotel;
}
MagicParser_parse("hotel_ids.xml","myRecordHandler","xml|RESPONSE/HOTEL/");
// here you now have an array of hotels, each items containing ID, NAME and LOWESTRATE
print_r($hotels);
?>
However, in your application, it may be more appropriate simply to render the output HTML that you require for each hotel within the myRecordHandler function itself. Processing of the second file (hotel information) can be done quite easilyy with Magic Parser provided that there is only ever going to be one hotel in the entire file. You can then process it separately for each block of information you require, for example:
xml|RESPONSE/SERVICES/SERVICE/
...for each service
xml|RESPONSE/GALLERY/PICTURE/
...for each picture
etc. etc.
Are you intending to create a single page with all the information contained within it?
The way you would go about this, in conjunction with the above example (but outputing some HTML this time); is to start with code similar to the above, then loop through each hotel in the array and then parse that file out for each block of information you need.
The following example will display the list of hotels, and the pictures for each one, although in this case only the first hotel. To "pretend" to construct the URL for the individual hotel data, what i've done here is greate a file called "hotel_565.xml", which is constructed from the ID value in the $hotels array.
View Output
<?php
require("MagicParser.php");
$hotels = array();
function myRecordHandler($record)
{
// create an array of the hotel information we want
$hotel = array();
$hotel["ID"] = $record["HOTEL_ID"];
$hotel["NAME"] = $record["HOTEL_NAME"];
$hotel["LOWESTRATE"] = $record["LOWESTRATE"];
// add this hotel to the global array
global $hotels;
$hotels[] = $hotel;
}
MagicParser_parse("hotel_ids.xml","myRecordHandler","xml|RESPONSE/HOTEL/");
// here you now have an array of hotels, each items containing ID, NAME and LOWESTRATE
foreach($hotels as $hotel)
{
print "<h1>".$hotel["NAME"]."</h1>";
$url = "hotel_".$hotel["ID"].".xml";
// Services
MagicParser_parse($url,"myServiceRecordHandler","xml|RESPONSE/SERVICES/SERVICE/");
// Pictures
MagicParser_parse($url,"myPictureRecordHandler","xml|RESPONSE/GALLERY/PICTURE/");
}
function myServiceRecordHandler($record)
{
print "<li>".$record["NAME"]."</li>";
if ($record["DESCRIPTION"])
{
print "<blockquote><small>".$record["DESCRIPTION"]."</small></blockquote>";
}
}
function myPictureRecordHandler($record)
{
print "<center>";
print "<img src='".$record["FILENAME"]."' /><br />";
print "<strong>".$record["NAME"]."</strong><br /><br />";
print "</center>";
}
?>
To display more information, simply copy the way the services / pictures have been handled above, with additional calls to MagicParser_parse() for each one.
Regarding your implementation; obviously since this involves parsing the second, hotel info feed multiple times, it would not be a good idea, either for performance or resources on your hotel partner; to keep requesting the remote XML by URL for each section. Instead, what you should do here is read the XML into a local variable, and then parse the local variable using Magic Parser's built in "string://" protocol handler instead of the actual URL.
To show you what I mean, where you have the following code in the above example:
foreach($hotels as $hotel)
{
print "<h1>".$hotel["NAME"]."</h1>";
$url = "hotel_".$hotel["ID"].".xml";
// Services
MagicParser_parse($url,"myServiceRecordHandler","xml|RESPONSE/SERVICES/SERVICE/");
// Pictures
MagicParser_parse($url,"myPictureRecordHandler","xml|RESPONSE/GALLERY/PICTURE/");
}
...it would be worth considering doing something like this (although I don't know the actual URL...):
foreach($hotels as $hotel)
{
print "<h1>".$hotel["NAME"]."</h1>";
// construct the hotel info URL
$url = "http://www.travelyucatan.com/get_hotelxml.php?id=".$hotel["ID"];
// download into the local variable $xml
$fp = fopen($url,"r");
$xml = "";
while(!feof($fp)) $xml .= fread($fp,1024);
fclose($fp);
// now we can parse the local variable $xml for each section required
// Services
MagicParser_parse("string://".$xml,"myServiceRecordHandler","xml|RESPONSE/SERVICES/SERVICE/");
// Pictures
MagicParser_parse("string://".$xml,"myPictureRecordHandler","xml|RESPONSE/GALLERY/PICTURE/");
}
Quite a bit to take in there i'm afraid, but I hope this helps! If ultimately because of this you decide that Magic Parser is not suitable for your application I will of course refund your purchase.
Cheers,
David.