D.N.S
Новичок
PHPInside #1 Статья: Чтение XML с использованием DOM
music.xml
music.php
Почему не работает этот код? =(
Ошибка: Fatal error: Call to undefined method DOMText::getElementsByTagName() in music.php on line 8
music.xml
Код:
[size=2][FONT=courier new]<music>
<artist id="1">
<name>The Rolling Stones</name>
<albums>
<title>Exile On Main Street</title>
</albums>
</artist>
<artist id="2">
<name>Aimee Mann</name>
<albums>
<title>I'm With Stupid</title>
<title>Bachelor No. 2</title>
</albums>
</artist>
</music>[/FONT][/size]
Код:
[PHP]<?php
$music = new domDocument;
$music->preserveWhiteSpace = false;
$music->load('music.xml');
$artists = $music->documentElement;
print "<table>\n";
foreach ($artists->childNodes as $artist) {
$names =$artist->getElementsByTagName('name');
$name = $names->item(0)->firstChild->nodeValue;
$titles =$artist->getElementsByTagName('title');
foreach ($titles as $title) {
print "<tr><td>$name</td>";
print "<td>" . $title->firstChild->nodeValue . "</td></tr>\n";
}
}
print "</table>\n";
?>[/PHP]
Ошибка: Fatal error: Call to undefined method DOMText::getElementsByTagName() in music.php on line 8