In this case, I think it would be best to parse at the BOOKINGRETRIEVALRS/BOOKINGS/BOOKING/ level - that way, you can them use the iteration pattern to extract any of the repeating child elements required. Consider the following example (with your example XML saved as bookings.xml)...
Hello vjeko,
In this case, I think it would be best to parse at the BOOKINGRETRIEVALRS/BOOKINGS/BOOKING/ level - that way, you can them use the iteration pattern to extract any of the repeating child elements required. Consider the following example (with your example XML saved as bookings.xml)...
<?php
require("MagicParser.php");
$data = file_get_contents("bookings.xml");
MagicParser_parse("string://".$data,"myRecordHandler","xml|BOOKINGRETRIEVALRS/BOOKINGS/BOOKING/");
function myRecordHandler($record)
{
global $bookingDetails;
$bookingDetail = array();
$bookingDetail["BOOKING-ID"] = $record["BOOKING-ID"];
$bookingDetail["HOTEL-ID"] = $record["HOTEL-ID"];
$specialRequests = array();
$i = "";
$p = "";
while(1)
{
if ($i) $p = "@".$i;
if (!isset($record["SPECIALREQUEST".$p."-CODE"])) break;
$code = $record["SPECIALREQUEST".$p."-CODE"];
$text = $record["SPECIALREQUEST".$p];
$specialRequests[$code] = $text;
$i++;
}
$bookingDetail["SPECIALREQUESTS"] = $specialRequests;
$bookingDetails[] = $bookingDetail;
}
print_r($bookingDetails);
?>
The output being:
Array
(
[0] => Array
(
[BOOKING-ID] => xx
[HOTEL-ID] => xx
[SPECIALREQUESTS] => Array
(
[1.14] => 1 king bed
[2.1] => Non-Smoking
[5] => Hotel Collect Booking Collect Payment From Guest
)
)
[1] => Array
(
[BOOKING-ID] => xx
[HOTEL-ID] => xx
[SPECIALREQUESTS] => Array
(
[5] => Hotel Collect Booking Collect Payment From Guest
[2.1] => Non-Smoking
[1.40] => 1 bed
)
)
)
Hope this helps!
Cheers,
David
--
MagicParser.com