SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    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>
    I'm trying to iterate through the entries with:
    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>';
        } 
    ...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.

  2. #2
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry - bad info given by me
    Last edited by foofoonet; Aug 14, 2006 at 01:28. Reason: I gave out wrong info - sorry
    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to feed it a string of xml, not a filename
    PHP Code:
    $sxml = new SimpleXmlElement(file_get_contents($xml_file));
    // or
    $sxml simplexml_load_file($xml_file);

    print_r($sxml); 

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [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]

  6. #6
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it will help anyone I solved this by enabling extension=php_openssl.dll

    THanks
    DD


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •