SimpleXML从XML获得固件版本

时间:2022-10-20 18:46:03

I'm trying to get the PS4 firmware version from their XML, but for some reason it's returning NULL.

我试图从他们的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.';
    }
?>

I have no idea what I'm doing wrong, because I've followed this article and it seems I've done it correctly.

我不知道我做错了什么,因为我已经阅读了这篇文章,看起来我做得很对。

Any ideas?

什么好主意吗?

2 个解决方案

#1


3  

If accessing the wrong element simplexml doesn't throw an error it just gives you the nothingness that your call returned. You should look at the structure to determine where in the structure your element is. In this case you are off by 1 element.

如果访问错误的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.';
}

#2


1  

Another option can be accessing attributes of a node with attributes() function:

另一种选择是使用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;

#1


3  

If accessing the wrong element simplexml doesn't throw an error it just gives you the nothingness that your call returned. You should look at the structure to determine where in the structure your element is. In this case you are off by 1 element.

如果访问错误的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.';
}

#2


1  

Another option can be accessing attributes of a node with attributes() function:

另一种选择是使用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;