I have searched on stack but no question or answer answers this question directly as far as I can tell.
I have this code below:
$xml_data = file_get_contents('http://www.test.co.uk/charts.xml');
$xml = new SimpleXMLElement($xml_data);
$artist = $xml->artists->artist->name;
echo $artist;
However when I run this code it only shows the first artist name, does any one know how I could get it to show all of the names in the xml file.
For your reference the xml file is laid out as follows:
<artists_chart start="" end="">
<period>Past 7 days</period>
<artists>
<artist gid="">
<name>Name1</name>
<plays>51</plays>
<previous_plays>53</previous_plays>
</artist>
<artist gid="">
<name>Name2</name>
<plays>45</plays>
<previous_plays>97</previous_plays>
</artist>
<artist gid="">
<name>Name3</name>
<plays>41</plays>
<previous_plays>39</previous_plays>
</artist>
</artists>
</artists_chart>
Thanks for any help or guidance.
1 Answer