SimpleXML从XML获取固件版本
问题描述:
我试图从他们的XML中获取PS4固件版本,但由于某种原因它返回NULL
。SimpleXML从XML获取固件版本
<?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;