我有一个包含一些数据的 XSPX 文件,它的结构是
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/">
<trackList>
<track>
<album></album>
<title>Welcome Song</title>
<location>http://mysite.com/song.mp3</location>
<duration>20000</duration>
<info>Information about the song</info>
</track>
</trackList>
</playlist>
我试图用 PHP 提取这些数据,但它给了我错误,有时什么也没有。
$data = new DOMDocument(); $data->load('http://full/path/to/tracklist.xspf');
if($data->load("http://full/path/to/tracklist.xspf")) {
foreach ($data->getElementsByTagName('trackList') as $track) {
$title = $track->getElementsByTagName('title')->item(0)->nodeValue;
$info = $track->getElementsByTagNameNS('info')->item(0)->nodeValue;
print($track);
}
}
我在哪里做错了?