简单XML 从 XML 获取固件版本

SimpleXML Get Firmware Version from XML

我正在尝试从他们的 XML 获取 PS4 固件版本,但由于某种原因它返回 NULL

<?php
    $list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml');

    if($list) {
        echo $list->system_pup[0]['label']; // get firmware version
    } else {
        echo 'Error opening the XML file.';
    }
?>

我不知道我做错了什么,因为我已经按照 this article 并且看起来我做对了。

有什么想法吗?

如果访问错误的元素 simplexml 不会抛出错误,它只会让您的调用返回空值。您应该查看结构以确定您的元素在结构中的位置。在这种情况下,您偏离了 1 个元素。

$list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml');
if($list) {
    //print_r($list);
    echo $list->region->system_pup[0]['label']; // get firmware version
} else {
    echo 'Error opening the XML file.';
}

另一个选项可以访问具有 attributes() 功能的节点的 属性

$list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml');

echo $list->region->system_pup->attributes()->label;