PHP XML calling attributes

tauphujedre

New Member
I posted something just like this, with no responses but it was because I didn't give enough data. I closed that one and made this one because it better describes. I wasn't planning on making this.My code:\[code\] <?php$q = $_GET['q'];$xml = simplexml_load_file("http://ws.spotify.com/search/1/track?q=".$q."");echo $xml->tracks . "<br />";$num = 0;foreach($xml->children() as $child){ $num ++; if($num < 5){ echo "<a href='".$child->attributes(href)."' title=''>".$child->name . " by " . $child->artist->name . "</a><br />"; }} ?>\[/code\]I'm trying to call an attirbute of "href" for track.On Spotify's website they show:\[code\]<?xml version="1.0" encoding="utf-8"?><tracks xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1"> <opensearch:Query role="request" startPage="1" searchTerms="foo"/> <opensearch:totalResults>768</opensearch:totalResults> <opensearch:startIndex>0</opensearch:startIndex> <opensearch:itemsPerPage>100</opensearch:itemsPerPage> <track href="http://stackoverflow.com/questions/10611072/spotify:track:3ZsjgLDSvusBgxGWrTAVto"> <name>The Pretender</name> <artist href="http://stackoverflow.com/questions/10611072/spotify:artist:7jy3rLJdDQY21OgRLCZ9sD"> <name>Foo Fighters</name> </artist> <id type="isrc">USRW30700007</id> <id type="isrc">USRW30700007</id> <track-number>1</track-number> <length>269.373000</length> <popularity>0.79251</popularity> </track> ...</tracks>\[/code\]
 
Back
Top