Can Simple XML be used, or do I have to use a different XML Parser?
This is the code I used to extract the data, and it works well. All the outputs are exactly as I wanted, so the variables are holding the correct data. Just need to know how to write back to the file using XML parsing.
Code: Select all
<?php
$xml = simplexml_load_file("Artist.xspf");
$i=0;
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
foreach($xml->tracklist->children() as $child)
{
echo $child->getName() . ": " . $child . " : ";
$songname[$i]= $xml->tracklist->track[$i]->annotation;
echo $songname[$i] . "<br />";
$tracklocation[$i]= $xml->tracklist->track[$i]->children();
echo "Song Location: " . $tracklocation[$i];
$songimage[$i]= $xml->tracklist->track[$i]->image;
echo "<br />Image URL = " . $songimage[$i] . "<br /><br />";
$i++;
}
echo "<br />Artist has " . $i . " tracks";
echo "<br />The 4th track's location is: " . $tracklocation[3];
echo "<br />It's name is " . $songname[3];
?>