XML Loop Statement in PHP -


hey, have simplexmlelement document features array of data artist's albums.

below extract of xml

  [2] => simplexmlelement object                     (                         [@attributes] => array                             (                                 [num] => 3                                 [type] => artist                             )                          [title] => dj tiësto                         [uri] => http://www.discogs.com/artist/dj+ti%c3%absto                         [summary] => dj tiësto tijs michiel verwest dutch trance dj & producer. 

in xml document there multiple different types of information artist info titles of albums. want extract parts of data , echo them out. instance want extract summary's of array entries have [type] defined artist. i'm guessing use foreach loop went through entries , checked if true? right way go it.

i apologise confusing explanation

---- edit ----

heres php code grabs data -

<?php  $curl = curl_init();  curl_setopt($curl, curlopt_url, "http://www.discogs.com/search?type=all&" . "q=dj+tiësto&" .  "f=xml&" .  "api_key=<key>");  curl_setopt($curl, curlopt_returntransfer, 1);  curl_setopt($curl, curlopt_encoding, "gzip");  $result = curl_exec($curl);  curl_close($curl);     $xmlmusic = new simplexmlelement($result,null,true);   foreach ($xmlmusic $xm)     {     $attrs = $xm->attributes();     if($attrs["type"] == "title")         echo $xm->summary."\n";     } 

?>

well, although possible duplication here simple example based on file.

i suppose have this:

<music>     <dj num="3" type="artist">         <title>dj tiesto</title>         <uri>http://www.discogs.com/artist/dj+ti%c3%absto</uri>         <summary>dj tiësto tijs michiel verwest dutch trance dj producer.</summary>     </dj>     <dj num="4" type="artist">         <title>title</title>         <uri>url</uri>         <summary>summary</summary>     </dj> 

in order extract summaries attribute type "title", asked, need this:

<?php     $result = file_get_contents("http://www.discogs.com/search?type=all&" .                "q=dj+tiësto&" .                 "f=xml&" .                 "api_key=<key>");      $xmlmusic = new simplexmlelement($result, null, false);      //print_r($xmlmusic);      foreach ($xmlmusic $xm)     {         $attrs = $xm->attributes();         if($attrs["type"] == "title")             echo $xm->summary."\n";     } ?> 

test yourself, works.


Comments