Advertisement
tamouse

rss feed handling

Nov 15th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. If you look at the feed from the USGS on Mag 5+ earthquakes over the
  2. past week at:
  3.  
  4. < http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M7.xml >
  5.  
  6. You will see these sorts of things in each entry:
  7.  
  8. <item>
  9. <pubDate>Sun, 06 Nov 2011 03:53:10 GMT</pubDate>
  10. <title>M 5.2, Oklahoma</title>
  11. <description>November 06, 2011 03:53:10 GMT</description>
  12. <link>http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usb0006klz.php</link>
  13. <geo:lat>35.5993</geo:lat>
  14. <geo:long>-96.7515</geo:long>
  15. <dc:subject>5</dc:subject>
  16. <dc:subject>pasthour</dc:subject>
  17. <dc:subject>5.00 km</dc:subject>
  18. <guid isPermaLink="false">usb0006klz</guid>
  19. </item>
  20.  
  21. The pubDate, title, description, link and guid tags are all part of
  22. the RSS standard. The geo: and dc: tags are not, and are specified in
  23. the opening rss tag:
  24.  
  25. <rss version="2.0"
  26. xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
  27. xmlns:dc="http://purl.org/dc/elements/1.1/">
  28.  
  29. by those xmlns attributes. So, unless you're lucky, almost any canned
  30. solution for dealing with RSS might not work with any particular feed.
  31.  
  32. The best solution I've come up with just using SimpleXML (or one of
  33. it's derivatives). Here's a quickie I wrote to test out the above
  34. link:
  35.  
  36. $feed_raw = file_get_contents("http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M2.5.xml");
  37. $feed = new SimpleXMLElement($feed_raw);
  38. $feed->registerXPathNamespace('geo','http://www.w3.org/2003/01/geo/wgs84_pos#');
  39. $feed->registerXPathNamespace('dc','http://purl.org/dc/elements/1.1/');
  40.  
  41. echo "<pre>";
  42. print_r($feed->getNamespaces(TRUE));
  43. print_r($feed->getDocNamespaces(TRUE));
  44. echo "</pre>";
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement