我有一个来自外部服务器的嵌套 xml,如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseDetails Language="en">
<SearchHotelPriceResponse>
<HotelDetails>
<Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"
Recommended = "true">
<City Code="AMS"><![CDATA[ Amsterdam ]]></City>
<Item Code="AME"><![CDATA[ AMERICAN ]]></Item>
</Hotel>
<Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"
Recommended = "true">
<City Code="AMS"><![CDATA[ Amsterdam ]]></City>
<Item Code="AME"><![CDATA[ AMERICAN2 ]]></Item>
</Hotel>
</HotelDetails>
</SearchHotelPriceResponse>
</ResponseDetails>
</Response>
考虑我可以在酒店内拥有许多其他级别,但第一个目标是获取Item
价值
我试过这样:
$hotelNodes = $xml_en->getElementsByTagName('Hotel');
foreach($hotelNodes as $hotel) {
//how to print item value?!
}
我必须再做一个getElementsByTagName
,或者可以用类似的$hotel->getElementsByTagName('Item')->nodeValue
东西或类似的东西来做这个?