Welcome Guest, Not a member yet? Register   Sign In
last.fm xml simplexml help needed
#1

[eluser]gullah[/eluser]
I'm trying to parse a last.fm xml response and keep getting the errors:

Severity: Warning

Message: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found


Message: simplexml_load_string() [function.simplexml-load-string]: &lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;

here is the code I'm using
Code:
$this->load->library('xmlrpc');
        $this->xmlrpc->server('http://ws.audioscrobbler.com/2.0/');
        $this->xmlrpc->method('artist.getSimilar');
        $request = array(
                                    array(
                                          // Param 0
                                          array('artist'=>'Beck',
                                          'api_key'=>'MYKEYHERE',
                                          'limit' => '4'),
                                          'struct'
                                    )
                               );
        $this->xmlrpc->request($request);
        //$this->xmlrpc->set_debug(TRUE);


        if ( ! $this->xmlrpc->send_request())
        {
            echo $this->xmlrpc->display_error();
        }
        $this->load->helper('xml');
        $string = xml_convert($this->xmlrpc->display_response());
        //$string = $this->xmlrpc->display_response();
        print_r('<pre>' . $string . '</pre>');
        $xml = simplexml_load_string($string);

Here is what the xml looks like when printed from string surrounded by <pre>'s
Code:
&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;
<lfm status=\"ok\">
<similarartists artist=\"Beck\">
<artist>
    <name>The Flaming Lips</name>
    <mbid>1f43d76f-8edf-44f6-aaf1-b65f05ad9402</mbid>
    <match>100</match>
    <url>www.last.fm/music/The+Flaming+Lips</url>
    <image size=\"small\">http://userserve-ak.last.fm/serve/34/80723.jpg</image>
    <image size=\"medium\">http://userserve-ak.last.fm/serve/64/80723.jpg</image>
    <image size=\"large\">http://userserve-ak.last.fm/serve/126/80723.jpg</image>
    <streamable>1</streamable>
</artist>
<artist>
    <name>Beck and The Flaming Lips</name>
    <mbid></mbid>
    <match>87.15</match>
    <url>www.last.fm/music/Beck+and+The+Flaming+Lips</url>
    <image size=\"small\">http://userserve-ak.last.fm/serve/34/38543.jpg</image>
    <image size=\"medium\">http://userserve-ak.last.fm/serve/64/38543.jpg</image>
    <image size=\"large\">http://userserve-ak.last.fm/serve/126/38543.jpg</image>
    <streamable>0</streamable>
</artist>
<artist>
    <name>Eels</name>
    <mbid>14387b0f-765c-4852-852f-135335790466</mbid>
    <match>80.48</match>
    <url>www.last.fm/music/Eels</url>
    <image size=\"small\">http://userserve-ak.last.fm/serve/34/231231.jpg</image>
    <image size=\"medium\">http://userserve-ak.last.fm/serve/64/231231.jpg</image>
    <image size=\"large\">http://userserve-ak.last.fm/serve/126/231231.jpg</image>
    <streamable>1</streamable>
</artist>
<artist>
    <name>Blur</name>
    <mbid>ba853904-ae25-4ebb-89d6-c44cfbd71bd2</mbid>
    <match>75.59</match>
    <url>www.last.fm/music/Blur</url>
    <image size=\"small\">http://userserve-ak.last.fm/serve/34/8668.jpg</image>
    <image size=\"medium\">http://userserve-ak.last.fm/serve/64/8668.jpg</image>
    <image size=\"large\">http://userserve-ak.last.fm/serve/126/8668.jpg</image>
    <streamable>1</streamable>
</artist>
</similarartists></lfm>

Thanks

Drew
#2

[eluser]Pascal Kriete[/eluser]
It's probably caused by this line:
Code:
$string = xml_convert($this->xmlrpc->display_response());

I'm not sure why you're doing that, but it will convert everything to entities, so it's no longer valid xml.
#3

[eluser]gullah[/eluser]
I found a much easier way of doing this rather than using the xmlrpc library.

Just in case anybody else is looking for something like this.
Code:
$xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=artist&api_key=YOURKEYHERE&limit=6');
            $xml_array = array();
            foreach($xml->xpath('similarartists/artist/name') as $artist)
            {//your code here}




Theme © iAndrew 2016 - Forum software by © MyBB