unpix
unpix

Reputation: 853

xml how to parse in php

I have this xml

http://www.scorespro.com/rss/live-soccer.xml

the structure is this :

 <rss>
 <channel>
 <item>
 <title>
 </title>
 </item>
 </channel>
 </rss>

I want to get the information about the titles, so i'm trying to do this, but without success.

  $xml = simplexml_load_file('http://www.scorespro.com/rss/live-soccer.xml');
foreach($xml->item as $item)
 {
 echo $item->title;
 } 

I already did print_r($xml) to see if is parsing correctly the url that i'm giving.

Upvotes: 0

Views: 100

Answers (1)

MrCode
MrCode

Reputation: 64526

$xml has root node, in this case <rss>:

foreach($xml->channel->item as $item)

You can also use XPath to get the items:

$items = $result = $xml->xpath('/rss/channel/item');

Upvotes: 1

Related Questions