20

I get a URL from a user. I need to know:
a) is the URL a valid RSS feed?
b) if not is there a valid feed associated with that URL

using PHP/Javascript or something similar

(Ex. http://techcrunch.com fails a), but b) would return their RSS feed)

Zoe
  • 27,060
  • 21
  • 118
  • 148
Gilean
  • 14,708
  • 10
  • 45
  • 52

6 Answers6

20

Found something that I wanted:

Google's AJAX Feed API has a load feed and lookup feed function (Docs here).

a) Load feed provides the feed (and feed status) in JSON

b) Lookup feed provides the RSS feed for a given URL

Theres also a find feed function that searches for RSS feeds based on a keyword.

Planning to use this with JQuery's $.getJSON

Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111
Gilean
  • 14,708
  • 10
  • 45
  • 52
  • Too bad you have to use Google Feeds API for that. RSS has a simple discovery mechanism based on elements in the section. It's very easy to implement and will remove one dependency on Google if you do that. – Julien Genestoux Jun 01 '14 at 20:08
10

The Zend Feed class of the Zend-framework can automatically parse a webpage and list the available feeds.

Example:

$feedArray = Zend_Feed::findFeeds('http://www.example.com/news.html');
Farzad
  • 842
  • 2
  • 9
  • 26
6

This link will allow you to validate the link against the RSS/Atom specifications using the W3C specs, but does require you to manually enter the url.

There are a number of ways to do this programmatically, depending on your choice of language - in PHP, parsing the file as valid XML is a good way to start, then compare it to the relevant DTD.

For b), if the link itself isn't a feed, you can parse it and look for a specified feed in the <head> section of the page, searching for a link whose type is "application/rss+xml", e.g:

<link rel="alternate" title="RSS Feed" 
    href="http://www.example.com/rss-feed.xml" type="application/rss+xml" />

This type of link is the one used by most browsers to "auto-discover" feeds (causing the RSS icon to appear in your address bar)

ConroyP
  • 40,958
  • 16
  • 80
  • 86
5

a) Retrieve it and try to parse it. If you can parse it, it's valid.

b) Test if it's an HTML document (server sent text/html) MIME-type. If so, run it through an HTML parser and look for <link> elements with RSS feed relations.

John Millikin
  • 197,344
  • 39
  • 212
  • 226
4

For Perl, there is Feed::Find , which does automate the discovery of syndication feeds from the webpage. The usage is quite simplicistic:

use Feed::Find;
my @feeds = Feed::Find->find('http://example.com/');

It first tries the link tags and then scans the a tags for files named .rss and something like that.

Corion
  • 507
  • 3
  • 5
2

Are you doing this in a specific language, or do you just want details about the RSS specification?

In general, look for the XML prolog:

<?xml version="1.0" encoding="UTF-8"?>

followed by an <rss> element, but you might want to validate it as XML, fully validate it against a DTD, or verify that - for example, each URL referred to is valid, etc. More detail would help.

UPDATE: Ah - PHP. I've found this library to be pretty useful: MagpieRSS

Bobby Jack
  • 15,689
  • 15
  • 65
  • 97