So this is an example xml that musicbrainz returns (for artist “Absynthe Minded” and song “Moodswing Baby”):
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
<recording-list offset="0" count="3">
<recording ext:score="100" id="580d3e6f-6b2a-4f2c-bb06-a73486de50b8">
<title>Moodswing Baby</title>
<length>230706</length>
<artist-credit>...</artist-credit>
<release-list>
<release id="f183e8a3-5326-44c9-8ab3-00a2dbb74caf">
<title>Absynthe Minded</title>
<status>Official</status>
<release-group type="Album"/>
<date>2009</date>
<country>BE</country>
<medium-list>...</medium-list>
</release>
<release id="fccd0f03-30e5-44ac-8825-a61ad8b25442">...</release>
<release id="b3873ea0-0ed3-48f1-9703-4f5302460d0e">...</release>
<release id="b68fb38c-5a5a-4d24-bd41-2c50945cef39">...</release>
</release-list>
<puid-list>...</puid-list>
<isrc-list>...</isrc-list>
</recording>
<recording ext:score="100" id="359c27e3-5153-445e-aa66-71d8152d19e4">...</recording>
<recording ext:score="31" id="e9e4628a-61ff-4dd7-8fbb-a8d655d29a5a">...</recording>
</recording-list>
</metadata>
I’m trying to print that country “BE” on my website next to the artists name with this at the moment:
<?php
$xml = simplexml_load_file("http://www.musicbrainz.org/ws/2/recording?query=moodswing%20baby%20AND%20artist:absynthe%20minded");
$info = $xml->recording-list->recording[1]->release-list->release[1]->country;
echo $info;
?>
I use the same method to retrieve song and artist infos from last.fm’s database (also xml) but it doesn’t seem to work with this (T_OBJECT_OPERATOR, expecting ‘(‘ error). I’ve tried to remove the [1] but no results.
Any ideas how I can retrieve and print that country? Thank you!
XML element names that contain characters which are not allowed in PHP variable names must be encased in braces or placed in variable first, e.g.,
$recordingList = 'recording-list'; $xml->$recordingList;. Also, arrays are zero-based:http://codepad.org/Yhz3V3wE