Can't solve SimpleXML Error: String could not be parsed as XML'

I have the following xml file that i’m trying to use to learn xml:
rss.xml:


<?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>

I’m trying to iterate through the entries with:


 $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>';
    }

…but am getting the error:

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

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.

Sorry - bad info given by me

I’m still none the wiser on this, and any hints would be appreciated.

I’m using v5.04 and my libxml version is 2.6.11. Are any of these versions a bit funky?

you need to feed it a string of xml, not a filename


$sxml = new SimpleXmlElement(file_get_contents($xml_file));
// or
$sxml = simplexml_load_file($xml_file);

print_r($sxml);

[Yes, I know this is an old thread, but I found this by Googling, and if it can help someone else…]

If you are passing it a filename instead of a string, the third parameter needs to be TRUE, e.g.:

$sxe = new SimpleXMLElement(‘they_wont_let_me_put_a_url_here’, NULL, TRUE);

if it isn’t, the constructor function expects a string.

RTFM here…

[sorry, they won’t let me post links]

If it will help anyone I solved this by enabling extension=php_openssl.dll

THanks
DD