如何在PHP中获取SOAP属性?

时间:2013-03-01 14:43:36

标签: php soap

使用下面的示例,我应该如何解析“HotelRef”的“HotelCode”属性?

<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] => )

1 个答案:

答案 0 :(得分: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'};
}