【问题标题】:How to Loop through XML subnodes using PHP's simplexml如何使用 PHP 的 simplexml 循环遍历 XML 子节点
【发布时间】:2011-05-07 08:04:38
【问题描述】:

好的,我在循环这些子节点时遇到问题。在本例中,我将向您展示我用来尝试从酒店信息提要中获取便利设施的代码。 XML 的格式似乎不太好,不幸的是我无法控制它。这是我的代码。

$xml = simplexml_load_file("http://www.2-20.com/hotelRoomSearchDetails.cfm?pnum_hotel_seq_id=210&pchr_room_type=STUDIO%22")
$hotel_amenities = $xml->contentDataResults->hotelContent->hotelAmenities;

foreach($hotel_amenities as $a){
    echo $a->amenity;
}

然而,它只是返回第一个便利设施。

【问题讨论】:

标签: php xml simplexml


【解决方案1】:
$hotel_amenities = $xml->contentDataResults->hotelContent->hotelAmenities->children();
foreach($hotel_amenities as $a)
{
  echo $a;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-27
    • 2013-11-02
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多