正在将 XML 导入到 Sql 数据库
Importing XML to Sql database
我有这个 xml:
-<lfm status="ok">
-<track>
<id>602366984</id>
<name>Barbarism Begins At Home (BBC TV Tube performance)</name>
<mbid/>
-<url>http://www.last.fm/music/The+Smiths/_/Barbarism+Begins+At+Home+(BBC+TV+Tube+performance)</url>
<duration>384000</duration>
<streamable fulltrack="0">0</streamable>
<listeners>10</listeners>
<playcount>24</playcount>
-<artist>
<name>The Smiths</name>
<mbid>40f5d9e4-2de7-4f2d-ad41-e31a9a9fea27</mbid>
<url>http://www.last.fm/music/The+Smiths</url>
</artist>
<toptags>
</toptags>
</track>
</lfm>
我想获取曲目和艺术家的名字,我应该为此使用 2 个代码(下一个代码)还是有更好的方法?
foreach ($xml -> track as $row) {
$title = $row -> name;
$artist = $row -> name;
$duration = $row -> duration;
在此代码中,我正在获取艺术家的名字。
foreach ($xml -> track as $row) {
$title = $row -> name;
$artist = $row ->artist-> name;
$duration = $row -> duration;
我有这个 xml:
-<lfm status="ok">
-<track>
<id>602366984</id>
<name>Barbarism Begins At Home (BBC TV Tube performance)</name>
<mbid/>
-<url>http://www.last.fm/music/The+Smiths/_/Barbarism+Begins+At+Home+(BBC+TV+Tube+performance)</url>
<duration>384000</duration>
<streamable fulltrack="0">0</streamable>
<listeners>10</listeners>
<playcount>24</playcount>
-<artist>
<name>The Smiths</name>
<mbid>40f5d9e4-2de7-4f2d-ad41-e31a9a9fea27</mbid>
<url>http://www.last.fm/music/The+Smiths</url>
</artist>
<toptags>
</toptags>
</track>
</lfm>
我想获取曲目和艺术家的名字,我应该为此使用 2 个代码(下一个代码)还是有更好的方法?
foreach ($xml -> track as $row) {
$title = $row -> name;
$artist = $row -> name;
$duration = $row -> duration;
在此代码中,我正在获取艺术家的名字。
foreach ($xml -> track as $row) {
$title = $row -> name;
$artist = $row ->artist-> name;
$duration = $row -> duration;