PHP标签的XML阅读器

时间:2018-03-19 16:41:06

标签: php xml

我在下面的pastebin中链接了这个XML文件名update.xml

https://pastebin.com/kFjX5Wka

现在我想输出如下:

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.');
}

这会返回制造商,但在解析他们的信息时被阻止了 所以有人能指出我正确的方向

2 个答案:

答案 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>";
}
相关问题