...

View Full Version : Simple xml - why won't it read my feed (code provided)



stfc_boy
03-05-2008, 02:31 PM
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)

http://www.slougheaz.org/query.jpg

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

Can anyone help?



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

_Aerospace_Eng_
03-05-2008, 02:52 PM
Because $v['name'] never equals that. Try

<?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";
}

}

?>

stfc_boy
03-05-2008, 03:55 PM
Thanks, but that's still outputting nothing? Any other suggestions please?

mlseim
03-05-2008, 04:21 PM
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";
}
}

stfc_boy
03-05-2008, 04:44 PM
Nope: Warning: Invalid argument supplied for foreach() ?

Sorry to be a pain!

mlseim
03-05-2008, 07:32 PM
Are you trying to read the RSS feed from this page?
http://www.empirecinemas.co.uk/index.php?page=nowshowing&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.

oesxyl
03-05-2008, 07:47 PM
Are you trying to read the RSS feed from this page?
http://www.empirecinemas.co.uk/index.php?page=nowshowing&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!



$ 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

mlseim
03-06-2008, 12:06 AM
I'm hoping he gives us the URL that he wants to read.

GJay
03-06-2008, 08:54 AM
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:


//site[name='Empire Birmingham Great Park']

should do it, then you can get the details from there.

stfc_boy
03-06-2008, 09:41 AM
Still no joy, so appreciate your helps on this. Here's the feed:

http://www.empirecinemas.co.uk/empire/_lib_local/xml/empire_rss.xml

Many Thanks

GJay
03-06-2008, 12:32 PM
The names have spaces round them, taking that into account then the xpath expression I gave works.

mlseim
03-06-2008, 03:24 PM
I got it!

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

Here is my PHP:


<?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($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# 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;
}
}
?>

stfc_boy
03-06-2008, 03:36 PM
Thanks guys,

Magic - i'm there now - thanks!!

Chris

oesxyl
03-06-2008, 03:54 PM
Still no joy, so appreciate your helps on this. Here's the feed:

http://www.empirecinemas.co.uk/empire/_lib_local/xml/empire_rss.xml

Many Thanks

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

best regards

mlseim
03-06-2008, 05:57 PM
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.

oesxyl
03-06-2008, 06:16 PM
What does that mean?

The site that creates the XML should make is smaller.
yes, I talk about compression when he create the file, this is not the OP site?


It's the biggest XML file I've seen.
medium, small, I have bigger than that, :)
I'm not sure, but freedict.org could have one bigger, :), and of course dmoz, :)
dmoz have few files, and total size more then 2G, last year, or two years ago, I can't remember when.

best regards

_Aerospace_Eng_
03-06-2008, 06:48 PM
No its not the OPs site so they have no control of the size or compression of the xml file.

oesxyl
03-06-2008, 07:30 PM
No its not the OPs site so they have no control of the size or compression of the xml file.

was a guess, :)



http://www.empirecinemas.co.uk/empire/_lib_local/xml/empire_rss.xml


they have no robots.txt, so I pressume is no problem, :)
anyway for a rss feed is huge, I hope OP don't fetch it on each request of his script :)

best regards

mlseim
03-06-2008, 08:25 PM
He should fetch it once each day using a CRON job,
and then cache the results.

It's a listing of movies at a theater, so once a day would be fine.

Skyzyx
03-13-2008, 06:06 AM
... anyway for a rss feed is huge...

It's not actually an RSS feed, but rather a custom XML feed. There's a bigger difference than you think. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum