How to access data from XML into php correctly ?

Hi,
I write code to parse XML data into php.

I can access some data. However, some data whith has im:name I cannot access it

http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=25/xml
[php]

<?php $html = ""; $url = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=25/xml"; $xml = simplexml_load_file($url); //echo $xml->entry[0]->title; for($i = 0; $i < 25; $i++){ $title = $xml->entry[$i]->title; $name = $xml->entry[$i]->name; $html .= "
$name
"; $html .= "$title"; } echo $html; ?>

[/php]

I solved the problem

[php]$html = “”;
$url = “http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=25/xml”;
$xml = simplexml_load_file($url);

$delete = ‘DELETE FROM song’;
$connection->query($delete);

//echo $xml->entry[0]->title;
for($i = 0; $i < 25; $i++){
$namespace = $xml->entry->getNameSpaces(true);
$x = $xml->entry[$i]->children($namespace[‘im’]);

   $title = $xml->entry[$i]->title;
   $name =mysqli_real_escape_string($connection, $x->name);
   $price =mysqli_real_escape_string($connection, $x->price);

   

     $html .= "$name";
	 $html .= "<br>$title";
	 $html .= "<br />$price<hr />";
	 
	 
   $Stitle= mysqli_real_escape_string($connection, $title);// to insert into DB 
	 $quiry = 'INSERT INTO song (title)'; // col in database
     $quiry .= "VALUES ('$Stitle')";  // variables that come from user which is decleare here 
     $result = mysqli_query($connection, $quiry);

if (!$result)
{ echo"1";
die(“Query Faile”. mysqli_errno($connection));
}

}
//echo $html;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service