2013-03-01 75 views
1

使用下面的例子,我應該如何解析「HotelRef」的「HotelCode」屬性?如何在PHP中獲取SOAP屬性?

<OTA_HotelAvailRQ Version="1.0" TimeStamp="2005-08-01T09:30:47+02:00" EchoToken="fb57388d" AvailRatesOnly="true" xmlns="http://www.opentravel.org/OTA/2003/05"> 
    <AvailRequestSegments> 
     <AvailRequestSegment AvailReqType="Room"> 
      <HotelSearchCriteria> 
       <Criterion> 
       <HotelRef HotelCode="HOTEL1"/> 
       </Criterion> 
      </HotelSearchCriteria> 
     </AvailRequestSegment> 
    </AvailRequestSegments> 
    </OTA_HotelAvailRQ> 

我能夠得到SOAP服務器的響應,請參閱下面的輸出,但注意到HotelRef是空的。我如何訪問屬性?

stdClass Object ( [AvailRequestSegments] => stdClass Object ( [AvailRequestSegment] => stdClass Object ( [HotelSearchCriteria] => stdClass Object ( [Criterion] => stdClass Object ( [HotelRef] => )

+0

祈求bejesus,你是不是用PHP訪問.NET SOAP服務。 (他們傾向於使用soap的非標準兼容版本,並且沒有php肥皂庫會與它們進行網格化) – Bingy 2013-03-01 14:49:43

+0

我不相信廠商在.NET上,因爲他們警告說使用.NET的客戶端可能存在問題 – jimbo2087 2013-03-01 14:51:03

回答

0
$strXML = 'theRequestXML_OTA_HotelAvailRQ'; 
$objSimpleXML = new SimpleXMLElement($strXML,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/"); 
foreach ($objSimpleXML->children() as $objItems) { 

    $strHotelCode = $objItems->AvailRequestSegments->AvailRequestSegment->HotelSearchCriteria->Criterion->HotelRef->attributes()->{'HotelCode'}; 
}