I have the following xml file that i'm trying to use to learn xml:
rss.xml:
I'm trying to iterate through the entries with:Code:<?xml version="1.0" encoding="utf-8"?> <channel id="Channel 76"> <title>My First RSS</title> <link>http://dev.discovery.com/demo/SOAP/</link> <description>booga booga</description> <language>en-us</language> <pubDate>Sun, 19 March 2006 21:25:29 -0500</pubDate> <image> <title>About.com</title> <url>http://z.about.com/d/lg/rss.gif</url> <link>http://about.com/</link> <width>88</width> <height>31</height> </image> <item> <title>And the Oscar goes to...</title> <link>http://classicalmusic.about.com/b/a/249503.htm</link> <description>Find out who won this year's Oscar for Best Music...</description> </item> <item> <title>And the Oscar goes to...</title> <link>http://classicalmusic.about.com/b/a/249503.htm</link> <description>Find out who won this year's Oscar for Best Music...</description> </item> </channel>
...but am getting the error:PHP Code:$xml_file = "rss.xml";
$sxml = new SimpleXmlElement($xml_file);
foreach($sxml->channel as $channel)
{
echo "<h1>{$channel['id']}</h1>";
echo '<ul>';
foreach($channel->item as $item)
{
echo '<li>Title: ' . $item->title . '</li>';
echo '<li>Description: ' . $item->description . '</li>';
}
echo '</ul>';
}
What does this mean? I can't find anything about it on the internet and it's been bugging me for about an hour now. I've tried outputting the strings using ->asXML(); but it makes no difference.Warning: Entity: line 1: parser error : Start tag expected, '<' not found in c:\wamp\www\discovery\www\demo\SOAP\index.php on line 19
Warning: rss.xml in c:\wamp\www\discovery\www\demo\SOAP\index.php on line 19
Warning: ^ in c:\wamp\www\discovery\www\demo\SOAP\index.php on line 19
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in c:\wamp\www\discovery\www\demo\SOAP\index.php:19 Stack trace: #0 c:\wamp\www\discovery\www\demo\SOAP\index.php(19): SimpleXMLElement->__construct('rss.xml') #1 {main} thrown in c:\wamp\www\discovery\www\demo\SOAP\index.php on line 19






Bookmarks