1. Go to this page and download the library: Download andrewfenn/xmlreader library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
echo "Hotel ID: ".$data->Hotel->attributes->HotelCode."\n";
/* Returns...
Hotel ID: 3
*/
foreach($data->find('Hotel') as $hotel) {
// Find a specific element's attribute
echo "Hotel ID: ".$hotel->attributes->HotelCode."\n";
}
foreach($data->children() as $tag) {
if ($tag->name == 'Hotel') {
echo "Hotel ID: ".$tag->attributes->HotelCode."\n";
}
}
/* Returns...
Hotel ID: 3
Hotel ID: 7
Hotel ID: 3
Hotel ID: 7
*/
// You can search for any tag attribute by prepending an @ infront of the attribute's name like so...
foreach($data->find('@HotelCode') as $hotel_code) {
echo "Hotel Code: ".$hotel_code."\n";
}
// You can search for any tag like so...
foreach($data->find('LengthsOfStay') as $los) {
echo "Length of Stay: ".$los->findFirst('@Time')." Days\n";
}
/* Returns...
Hotel Code: 3
Hotel Code: 4
Length of Stay: 3 Days
Length of Stay: 7 Days
*/