How to read data from XML file using php

391 views Asked by At

I want to read data from the below xml file using php code.

below is the XML file and i want to read data from it.

<availabilityRS xmlns="http://www.hotelbeds.com/schemas/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.hotelbeds.com/schemas/messages">
<auditData processTime="4331" timestamp="2016-12-08 11:05:49.211" requestHost="182.48.20.151" serverId="sa37AUX3ROLBLIS.env" environment="[int]" release="8629cf6ef0a2deed178b86daa0e13c79b5c99237" internal="0|D4A049C5629A4D3B81ED8C1609B92A30|UK|06|1|39||||||||||||25||1~1~2~0|||||vgw3t5723ryk95m4q58m3g87||"/>
<hotels checkIn="2016-12-15" checkOut="2016-12-16" total="1">
<hotel code="1070" name="Armadams" categoryCode="4EST" categoryName="4 STARS" destinationCode="PMI" destinationName="Majorca" zoneCode="10" zoneName="Palma" latitude="39.568861" longitude="2.630294" minRate="69.34" maxRate="224.00" currency="EUR">
<rooms>
<room code="DBT.ST" name="Double or Twin STANDARD">
<rates>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- FIT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="69.34" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="69.34" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="70.32" sellingRate="80.00" hotelSellingRate="80.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="8.00" commissionVAT="1.68" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="80.00" hotelAmount="80.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="69.79" sellingRate="80.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="69.79" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- FIT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="96.18" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="96.18" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="96.69" sellingRate="110.00" hotelSellingRate="110.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="11.00" commissionVAT="2.31" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="110.00" hotelAmount="110.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="95.97" sellingRate="110.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="95.97" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- FIT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="140.92" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="140.92" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="140.64" sellingRate="160.00" hotelSellingRate="160.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="16.00" commissionVAT="3.36" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="160.00" hotelAmount="160.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="139.57" sellingRate="160.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="139.57" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
</rates>
</room>
<room code="DBT.SU" name="Double or Twin SUPERIOR">
<rates>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- FIT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="91.70" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="91.70" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.SU|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="93.17" sellingRate="106.00" hotelSellingRate="106.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="10.60" commissionVAT="2.23" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="106.00" hotelAmount="106.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="92.47" sellingRate="106.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="92.47" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- FIT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="118.54" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="118.54" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="118.65" sellingRate="136.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="118.65" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.SU|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="119.54" sellingRate="136.00" hotelSellingRate="136.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="13.60" commissionVAT="2.86" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="136.00" hotelAmount="136.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- FIT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="163.28" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="163.28" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|DBT.SU|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="163.49" sellingRate="186.00" hotelSellingRate="186.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="18.60" commissionVAT="3.91" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="186.00" hotelAmount="186.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|DBT.SU|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="162.25" sellingRate="186.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="162.25" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
</rates>
</room>
<room code="TPL.ST" name="TRIPLE STANDARD">
<rates>
<rate rateKey="20161215|20161216|H|1|1070|TPL.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="94.93" sellingRate="108.00" hotelSellingRate="108.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="10.80" commissionVAT="2.27" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="108.00" hotelAmount="108.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|TPL.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="94.22" sellingRate="108.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="94.22" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|TPL.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="121.30" sellingRate="138.00" hotelSellingRate="138.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="13.80" commissionVAT="2.90" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="138.00" hotelAmount="138.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|TPL.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="120.40" sellingRate="138.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="120.40" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|TPL.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="165.25" sellingRate="188.00" hotelSellingRate="188.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="18.80" commissionVAT="3.95" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="188.00" hotelAmount="188.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|TPL.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="164.00" sellingRate="188.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="164.00" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
</rates>
</room>
<room code="JSU.ST" name="JUNIOR SUITE STANDARD">
<rates>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- FIT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="123.02" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="123.02" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|JSU.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="126.58" sellingRate="144.00" hotelSellingRate="144.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="14.40" commissionVAT="3.02" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="144.00" hotelAmount="144.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="125.62" sellingRate="144.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="125.62" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- FIT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="149.86" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="149.86" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="151.80" sellingRate="174.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="151.80" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|JSU.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="152.95" sellingRate="174.00" hotelSellingRate="174.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="17.40" commissionVAT="3.65" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="174.00" hotelAmount="174.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- FIT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="194.60" allotment="99" rateCommentsId="1|94855|3" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="194.60" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|JSU.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="196.90" sellingRate="224.00" hotelSellingRate="224.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="22.40" commissionVAT="4.70" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="224.00" hotelAmount="224.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|JSU.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="195.40" sellingRate="224.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="195.40" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
</rates>
</room>
<room code="QUA.ST" name="QUADRUPLE STANDARD">
<rates>
<rate rateKey="20161215|20161216|H|1|1070|QUA.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="115.15" sellingRate="131.00" hotelSellingRate="131.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="13.10" commissionVAT="2.75" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="131.00" hotelAmount="131.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|QUA.ST|CG- MERCHANT|RO||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="114.28" sellingRate="131.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="RO" boardName="ROOM ONLY" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="114.28" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|QUA.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="141.52" sellingRate="161.00" hotelSellingRate="161.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="16.10" commissionVAT="3.38" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="161.00" hotelAmount="161.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|QUA.ST|CG- MERCHANT|BB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="140.46" sellingRate="161.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="BB" boardName="BED AND BREAKFAST" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="140.46" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|W|1|1070|QUA.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="184.06" sellingRate="211.00" hotelMandatory="true" allotment="99" rateCommentsId="1|90440|96" paymentType="AT_WEB" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="184.06" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
<rate rateKey="20161215|20161216|H|1|1070|QUA.ST|CG- MERCHANT|HB||1~2~0||N@D4A049C5629A4D3B81ED8C1609B92A30" rateClass="NOR" rateType="BOOKABLE" net="185.47" sellingRate="211.00" hotelSellingRate="211.00" hotelCurrency="EUR" hotelMandatory="true" allotment="99" commission="21.10" commissionVAT="4.43" commissionPCT="10.00" rateCommentsId="1|90440|96" paymentType="AT_HOTEL" packaging="false" boardCode="HB" boardName="HALF BOARD" rooms="1" adults="2" children="0" childrenAges="">
<cancellationPolicies>
<cancellationPolicy amount="211.00" hotelAmount="211.00" hotelCurrency="EUR" from="2016-12-12T23:59:00+01:00"/>
</cancellationPolicies>
</rate>
</rates>
</room>
</rooms>
<creditCards>
<creditCard code="VI" name="VISA-SSL" paymentType="AT_HOTEL"/>
<creditCard code="AE" name="AMEX-SSL" paymentType="AT_HOTEL"/>
<creditCard code="MC" name="ECMC-SSL" paymentType="AT_HOTEL"/>
<creditCard code="DC" name="DINERS-SSL" paymentType="AT_HOTEL"/>
</creditCards>
</hotel>
</hotels>
</availabilityRS>

I have tried like this code to retrieve data from the xml.

Below I have attached the code used to retrieve data from the xml

$xml  = simplexml_load_string("myxml.xml");
foreach($xml as $hotel) { 
   echo "Hotel Name: ".$hotel->hotel['name']."<br>";
   echo "Hotel Category: ".$hotel->hotel['categoryName']."<br>";
   echo "Hotel Destination: ".$hotel->hotel['destinationName']."<br>";
   echo "Room Name: ".$hotel->hotel->rooms->room['name']."<br>";
   //echo "<br>"; 
}

But the result is

Hotel Name: 
Hotel Category: 
Hotel Destination: 
Room Name: 
Hotel Name: Armadams
Hotel Category: 4 STARS
Hotel Destination: Majorca
Room Name: Double or Twin STANDARD

All room data are not getting and displaying, is there any other way to read data from xml?

3

There are 3 answers

1
mononoke On BEST ANSWER

sample code below can help:

<?php
$availabilityrs = simplexml_load_file('temp.xml');
$hotel = $availabilityrs->hotels->hotel;
$room_nodes = $hotel->rooms->room;
foreach ($room_nodes as $room) {
    echo "Hotel Name: ".$hotel['name']."\n";
    echo "Hotel Category: ".$hotel['categoryName']."\n";
    echo "Hotel Destination: ".$hotel['destinationName']."\n";
    echo "Room Name: ".$room['name']."\n";
}

please refer this manul:

When multiple instances of an element exist as children of a single parent element, normal iteration techniques apply.

If hotel is mutiple, you should iterate it too.

6
Jirka Hrazdil On

$xml in your code probably refers to root element, that is <availabilityRS>. You need to change your loop to get to <hotels> and <hotel>s. and their rooms. Also you'll need to change simplexml_load_string to simplexml_load_file if you are reading XML data from a file:

$xml = simplexml_load_file(__DIR__.'/myxml.xml');

foreach ($xml->hotels[0] as $hotel) {
    echo $hotel['name']."<br>";
    echo $hotel['categoryName']."<br>";
    echo $hotel['destinationName']."<br>";
    echo "rooms:<br>";
    foreach ($hotel->rooms[0] as $room) {
        echo $room['name']."<br>";
    }
}
3
Wolverine On

Traversing XML elements the object-oriented way could be messy for some people. It's better have them converted to array elements and it then makes easier to iterate through them. Here is the code to convert the XML object to array and traversing through them:

$xml = simplexml_load_file('myxml.xml');
$xml = json_decode(json_encode($xml), true);
$hotel = $xml['hotels']['hotel'];

foreach($hotel['rooms'] as $rooms) {
    foreach($rooms as $room) {
        echo "<p>Hotel Name: {$hotel['@attributes']['name']}</p>";
        echo "<p>Hotel Category: {$hotel['@attributes']['categoryName']}</p>";
        echo "<p>Hotel Destination: {$hotel['@attributes']['destinationName']}</p>";
        echo "<p>Room Name: {$room['@attributes']['name']}</p>";
        echo "<br><br>";
    }
}

Hope it helps!