属性を含む要素にアクセスしようとしています=一定の値です。私はExpedia APIを使用していますので、動作させることはできません。ここではその後xmlとphpの特定の値と一致する要素の属性を取得する
$ch = curl_init();
$fp = fopen('room.xml','w');
curl_setopt($ch, CURLOPT_URL, "http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=13&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale=en_US¤cyCode=USD&customerIpAddress=10.184.2.9&customerUserAgent=Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/535.11+(KHTML,+like+Gecko)+Chrome/17.0.963.79+Safari/535.11&customerSessionId=&xml=<HotelInformationRequest><hotelId>".$hid."</hotelId><options>0</options></HotelInformationRequest>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
$val = curl_exec($ch);
curl_close($ch);//Close curl session
fclose($fp); //Close file overwrite
$data = simplexml_load_file('room.xml');
XML応答の例である:ここで私はxmlファイルに接続しています方法です
<ns2:HotelInformationResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/" hotelId="121196">
<customerSessionId>0ABAA871-3187-D691-3682-CC27421918AC</customerSessionId>
<HotelSummary order="0">...</HotelSummary>
<HotelDetails>...</HotelDetails>
<Suppliers size="2">...</Suppliers>
<RoomTypes size="9">
<RoomType roomCode="17918" roomTypeId="136767">
<description>Deluxe Sunset View</description>
<descriptionLong>
One king or two double beds. 38.5 meters (414 square feet). Floors 1–9. Complimentary wireless Internet access. CD/DVD player. MP3 docking station. Complimentary newspapers. Minibar. Coffeemaker. Bathroom with shower only. Aveda toiletries. Bathrobes. Bathroom scale. Laptop-compatible safe. Turndown service.
</descriptionLong>
</RoomType>
</RoomTypes>
そして最後に、ここでは、私はそれにアクセスしようとしている方法です:
<?php $dataroom = $data->RoomTypes->RoomType['@roomCode="17918"']->description; var_dump($dataroom); ?>
ご覧のとおり、roomCode = 17918の説明にアクセスしようとしていますが、動作しません。私はエコーと印刷を使用して試して何も動作しません。 var_dumpはNULLの値を返します。私は何が間違っているのか分からない。私は私が欲しい他の要素を得ることができますが、私はそれが必要な場所ではありません。
おそらく 'description 'の最後に' - > data'を付けるべきでしょうか? –
nope :(動作しませんでした。 – liveandream