给定一个更大的 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
each 的属性,然后是每天CalendarDay
的元素数组。RoomTypeInventory
肥皂信封中的所有名称空间都已注册。
这是我的代码的要点('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');
我注册了命名空间“x”,因为它是使用 CalendarDay 声明的默认命名空间。
$CalendarDay->attributes()->Date
有正确的值。但是$RoomTypeInventory
是空的。我也试过
$RoomTypeInventory = $CalendarDay->xpath('x:Occupancy/x:RoomTypeInventory');
这也失败了。但
$Occupancy = $CalendarDay->xpath('x:Occupancy');
返回一个适当的值,所以我假设命名空间是正确的。
我究竟做错了什么?