Monday 15 March 2010

xml - PHP Get Attribute -



xml - PHP Get Attribute -

i'm trying parse xml has format:

<lfm status="ok"> <album> <name>babel</name> <artist>mumford , sons</artist> <id>310716066</id> <mbid/> <url> http://www.last.fm/music/+noredirect/mumford+and+sons/babel </url> <releasedate></releasedate> <image size="small">http://userserve-ak.last.fm/serve/34s/85199619.jpg</image> <image size="medium">http://userserve-ak.last.fm/serve/64s/85199619.jpg</image> <listeners>4621</listeners> <playcount>151324</playcount> <tracks></tracks> <toptags> <tag> <name>indie</name> <url>http://www.last.fm/tag/indie</url> </tag> </toptags> </album> </lfm>

but when this:

//chamar api last.fm $album_response = file_get_contents("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=9ba08c332660c8e23d8612e296696236&artist=$artista&album=$album"); //criar um domdocument $xml= new domdocument('1.0', 'iso-8859-1'); $xml->loadxml($album_response); //ver se o álbum existe $encontrou_album = $xml->getelementsbytagname("lfm")->item(0)->getattribute("status");

the lastly line doesn't work. thoughts on how retrieve attribute?

xml dom

No comments:

Post a Comment