Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    Simple xml - why won't it read my feed (code provided)

    Hi All,

    I'm trying to read the 2nd part of this XML feed where the name = . Birmingham Empire Great Park. (i.e.ignoring the first part)



    However, this outputs nothing and I don't see why.

    Can anyone help?

    PHP Code:
    <?php

    $xml 
    simplexml_load_file('feed.xml');

    foreach (
    $xml->xpath('//site') as $v


    if (
    $v['name']=="Birmingham Empire Great Park")

        {    
        echo 
    "<h2>{$v->film->titel}</h2>" "\n";
        echo 
    "<p>{$v->film->tenwordsynopsis}</p>" "\n";
        echo 
    "<p>{$v->film->website}</p>" "\n";
        echo 
    "<p>{$v->film->rating}</p>" "\n";
        echo 
    "<p>{$v->film->showtime->day}</p>" "\n";
        }
        
    }

    ?>
    Thanks

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Because $v['name'] never equals that. Try
    PHP Code:
    <?php

    $xml 
    simplexml_load_file('feed.xml');

    foreach (
    $xml->xpath('//site') as $v


    if (
    str_replace('Empire ','',$v['name']) == "Birmingham Empire Great Park")

        {    
        echo 
    "<h2>{$v->film->titel}</h2>" "\n";
        echo 
    "<p>{$v->film->tenwordsynopsis}</p>" "\n";
        echo 
    "<p>{$v->film->website}</p>" "\n";
        echo 
    "<p>{$v->film->rating}</p>" "\n";
        echo 
    "<p>{$v->film->showtime->day}</p>" "\n";
        }
        
    }

    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts
    Thanks, but that's still outputting nothing? Any other suggestions please?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I think the part in blue is what you need ...

    $xml = simplexml_load_file('feed.xml');
    foreach ($xml->empire->site as $v) {
    if($v->name === "Birmingham Empire Great Park"){
    echo "<h2>{$v->film->title}</h2>" . "\n";
    echo "<p>{$v->film->tenwordsynopsis}</p>" . "\n";
    echo "<p>{$v->film->website}</p>" . "\n";
    echo "<p>{$v->film->rating}</p>" . "\n";
    echo "<p>{$v->film->showtime->day}</p>" . "\n";
    }
    }
    Last edited by mlseim; 03-05-2008 at 04:25 PM.

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts
    Nope: Warning: Invalid argument supplied for foreach() ?

    Sorry to be a pain!

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Are you trying to read the RSS feed from this page?
    http://www.empirecinemas.co.uk/index...tbx_site_id=33

    Give us a link to the actual XML file you are reading.
    Then I can try some things out by myself.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by mlseim View Post
    Are you trying to read the RSS feed from this page?
    http://www.empirecinemas.co.uk/index...tbx_site_id=33

    Give us a link to the actual XML file you are reading.
    Then I can try some things out by myself.
    this is broken!

    Code:
    $ rapper -i rss-tag-soup http://www.empirecinemas.co.uk/index.php?page=nowshowing\&tbx_site_id=33
    rapper: Parsing URI http://www.empirecinemas.co.uk/index.php?page=nowshowing&tbx_site_id=33
    rapper: Error - URI http://www.empirecinemas.co.uk/index.php?page=nowshowing&tbx_site_id=33:16 - XML parser error - Opening and ending tag mismatch: link line 0 and head
    rapper: Error - URI http://www.empirecinemas.co.uk/index.php?page=nowshowing&tbx_site_id=33:16 - XML Parsing failed
    rapper: Error - URI http://www.empirecinemas.co.uk/index.php?page=nowshowing&tbx_site_id=33 - Failed writing body
    rapper: Failed to parse URI http://www.empirecinemas.co.uk/index.php?page=nowshowing&tbx_site_id=33 rss-tag-soup content
    rapper: Parsing returned 0 triples
    best regards

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I'm hoping he gives us the URL that he wants to read.

  • #9
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the XML you posted has "Empire Birmingham" but your code is checking for "Birmingham Empire"...that won't be helping.

    You can use Xpath for the whole search though:
    Code:
    //site[name='Empire Birmingham Great Park']
    should do it, then you can get the details from there.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #10
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts
    Still no joy, so appreciate your helps on this. Here's the feed:

    http://www.empirecinemas.co.uk/empir...empire_rss.xml

    Many Thanks

  • #11
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    The names have spaces round them, taking that into account then the xpath expression I gave works.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I got it!

    Here is my test site:
    http://www.catpin.com/empire.php

    Here is my PHP:
    PHP Code:
    <?php  
    // rss page for Empire Cinemas -  
    $feed_url "http://www.empirecinemas.co.uk/empire/_lib_local/xml/empire_rss.xml";  

    # INITIATE CURL. 
    $curl curl_init(); 

    # CURL SETTINGS. 
    curl_setopt($curlCURLOPT_URL,"$feed_url"); 
    curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

    # GRAB THE XML FILE. 
    $xmlTwitter curl_exec($curl); 

    curl_close($curl); 

    # SET UP XML OBJECT. 
    // Use either one of these depending on
    // PHP4 or PHP5 and configuration.
    // Comment-out the one you are not using.
    //$xml = new SimpleXMLElement($xmlTwitter);
    $xml simplexml_load_string($xmlTwitter); 

    // Notice:  They spelled "titel" wrong in
    // their XML, so it is referenced that way.

    foreach ($xml->site as $item) { 
    $theater $item->name
    if(
    strpos($item->name"Great")){
    echo
    "$theater\n"
       foreach (
    $xml->site->film as $f) {
       echo 
    "<h2>{$f->titel}</h2>" "\n";
       echo 
    "<p>{$f->tenwordsynopsis}</p>" "\n";
       echo 
    "<p>{$f->website}</p>" "\n";
       echo 
    "<p>{$f->rating}</p>" "\n";
       echo 
    "<p>{$f->showtime->day}</p>" "\n";
       }
    exit;
    }

    ?>
    Last edited by mlseim; 03-06-2008 at 03:28 PM.

  • Users who have thanked mlseim for this post:

    stfc_boy (03-06-2008)

  • #13
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts
    Thanks guys,

    Magic - i'm there now - thanks!!

    Chris

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by stfc_boy View Post
    Still no joy, so appreciate your helps on this. Here's the feed:

    http://www.empirecinemas.co.uk/empir...empire_rss.xml

    Many Thanks
    turn on compression for xml, instead of 2M will be about 220k

    best regards

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Quote Originally Posted by oesxyl View Post
    turn on compression for xml, instead of 2M will be about 220k

    best regards
    What does that mean?

    The site that creates the XML should make is smaller.
    It's the biggest XML file I've seen.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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