我在下面的pastebin中链接了这个XML文件名update.xml
现在我想输出如下:
Manufacturer Google:
Device codename: angler
Download: download tag link here from <angler>
Device codename: bullhead
Download: download tag link here from <bullhead>
Manufacturer OnePlus:
Device codename: cheeseburger
Download: download tag link here from <cheeseburger>
Device codename: dumpling
Download: download tag link here from <dumpling>
到目前为止我有什么
if (file_exists('update.xml')) {
$xml = simplexml_load_file('update.xml');
foreach($xml as $manufacturer){
echo $manufacturer['id'] . "<br>";
}
} else {
exit('Failed to open update.xml.');
}
这会返回制造商,但在解析他们的信息时被阻止了 所以有人能指出我正确的方向
答案 0 :(得分:1)
您需要进一步检查每个children
的{{1}}:
manufacturer
答案 1 :(得分:0)
这会有效!
$xml = new SimpleXMLElement($xmlString);
foreach ($xml->manufacturer as $manufacturer){
echo "Manufacturer {$manufacturer['id']}:<br><br>";
foreach ($manufacturer as $codename => $v){
echo "Device codename: {$codename}<br>";
echo "Download: {$v->download}<br>";
}
echo "<hr>";
}