On Tue, 15 Nov 2011 20:30:29 +0000, Christopher Lee <ctlee@xxxxxxxxxxx> sent:
Hello All,
I am interested in importing RSS Feed content into a MySQL database
and displaying the aggregated content on a website. I am thinking of
developing the website within a CMS type framework (i.e. Drupal).
If anyone can refer me to any resources in this area then that
would be great. I hope that I have adequately explained my needs.
Thank you all in advance for your help.
First of all, note that not all RSS feeds are the same. Some contain
information and tags that go far beyond the scope of the RSS
standard. Frequently (and hopefully!) these are in different name
spaces. I'll give an example:
If you look at the feed from the USGS on Mag 5+ earthquakes over the
past week at:
< http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M7.xml >
You will see these sorts of things in each entry:
<item>
<pubDate>Sun, 06 Nov 2011 03:53:10 GMT</pubDate>
<title>M 5.2, Oklahoma</title>
<description>November 06, 2011 03:53:10 GMT</description>
<link>http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usb0006klz.php</link>
<geo:lat>35.5993</geo:lat>
<geo:long>-96.7515</geo:long>
<dc:subject>5</dc:subject>
<dc:subject>pasthour</dc:subject>
<dc:subject>5.00 km</dc:subject>
<guid isPermaLink="false">usb0006klz</guid>
</item>
The pubDate, title, description, link and guid tags are all part of
the RSS standard. The geo: and dc: tags are not, and are specified in
the opening rss tag:
<rss version="2.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
by those xmlns attributes. So, unless you're lucky, almost any canned
solution for dealing with RSS might not work with any particular feed.
The best solution I've come up with just using SimpleXML (or one of
it's derivatives). Here's a quickie I wrote to test out the above
link:
$feed_raw =
file_get_contents("http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M2.5.xml");
$feed = new SimpleXMLElement($feed_raw);
$feed->registerXPathNamespace('geo','http://www.w3.org/2003/01/geo/wgs84_pos#');
$feed->registerXPathNamespace('dc','http://purl.org/dc/elements/1.1/');
echo "<pre>";
print_r($feed->getNamespaces(TRUE));
print_r($feed->getDocNamespaces(TRUE));
echo "</pre>";
(I know these are going to get wrapped and possibly garbled. See here
for a better view: http://pastebin.com/6k7JPydX)
I really like using SimpleXML -- so far it's met pretty much all my
needs regarding parsing and handling XML data.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php