より大きなSOAP応答のこのフラグメントを考えると、次のようになります。
<Calendar>
<CalendarDay Date="2013-10-01" xmlns="http://webservices.micros.com/og/4.3/Availability/">
<Occupancy>
<RoomTypeInventory roomTypeCode="2BS" totalRooms="26" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="26" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="3BS" totalRooms="4" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="4" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="BSV" totalRooms="3" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="3" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="CHV" totalRooms="1" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="1" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="D3B" totalRooms="6" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="6" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="DLDB" totalRooms="86" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="86" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="DLDC" totalRooms="81" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="81" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="DLKB" totalRooms="123" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="123" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="DLKC" totalRooms="117" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="117" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="GDDB" totalRooms="4" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="4" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="GDDC" totalRooms="17" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="17" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="GDKB" totalRooms="20" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="20" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
<RoomTypeInventory roomTypeCode="GMS" totalRooms="3" overBookingLimit="0" soldDeductible="0" soldNonDeductible="0" totalAvailableRooms="3" xmlns="http://webservices.micros.com/og/4.3/HotelCommon/"/>
</Occupancy>
</CalendarDay>
<CalendarDay Date="2013-10-02" xmlns="http://webservices.micros.com/og/4.3/Availability/">
...
</CalendarDay>
</Calendar>
Date
それぞれの属性が必要で、次に各日の要素CalendarDay
の配列が必要です。RoomTypeInventory
soapEnvelopeのすべての名前空間が登録されました。
これが私のコードの要点です(「a」は以前に登録されたデフォルトの名前空間です):
$CalendarDays = $responseXML->xpath('//a:CalendarDay');
foreach($CalendarDays as $CalendarDay){
$CalendarDate = ($CalendarDay->attributes()->Date);
echo $CalendarDate . " ";
$CalendarDay->registerXPathNamespace('x', 'http://webservices.micros.com/og/4.3/Availability/');
$RoomTypeInventory = $CalendarDay->xpath('//x:RoomTypeInventory');
}
$responseXML = simplexml_load_file('FetchAvailablePackages60Days.resp.xml');
CalendarDayで宣言されたデフォルトの名前空間であるため、名前空間'x'を登録しました。
$CalendarDay->attributes()->Date
正しい値を持っています。しかし$RoomTypeInventory
、空です。私も試しました
$RoomTypeInventory = $CalendarDay->xpath('x:Occupancy/x:RoomTypeInventory');
これも失敗します。だが
$Occupancy = $CalendarDay->xpath('x:Occupancy');
適切な値を返すので、名前空間は正しいと思います。
私は何が間違っているのですか?