"The idea to create an OPML autodiscovery bookmarklet came up last Friday in a very inspiring conversation with James Corbett.
I started the IM chat by asking James if he "had a minute", and if he knew of a way to make
hyperlinks to OPML files on anyone’s website to automatically open in
Grazr. After a while it turned out that for months James had been
thinking along slightly different, but converging lines: wouldn’t it be cool if OPML
files could be auto-discovered, similar to what Firefox has been doing
for RSS feeds?"
I’d like to present my first, serious attempt to create a browser add-on that hopefully will prove to be useful to some: an OPML Auto-discovery Bookmarklet that displays a list of hyperlinks to the OPML files that have been made available by the author of any web page.
So, what is auto-discovery anyway? Most Firefox users are familiar with the orange feed icon to the right of the address bar, indicating that there’s an RSS feed attached to the page they are viewing. This mechanism is called auto-discovery. There’s not much magic about it: web page authors deliberately enable auto-discovery by linking to feed urls with an (x)html tag named <link> in the source code of their pages. Auto-discovery of OPML files is based on the same principle: detecting <link> tags in the header of a web page.

The OPML Auto-discovery Bookmarklet scans the header of a website and displays a list of OPML outline files in a box in the top-left corner of the browser. For completeness’ sake any RSS feeds are listed too. Because of the debate about the proper contents of the "rel" and "type" attributes for outline files I decided to be liberal what to accept: any "href"attribute that contains the text "opml" is accepted. (Update 2006-10-18: I slightly altered the code to also catch those OPML files that use a file extension of ‘.xml’ and have their type attribute set to ‘text/xml+opml’ or ‘text/x-opml’)
Below is a screenshot of what the CleverClogs header looks like, for example:

The bookmarklet lists each of these files as Grazr hyperlinks: when you click on any of these a Grazr window is opened in a new tab, displaying the contents of the OPML file or the RSS feed. Note that if a "title" attribute is provided, the bookmarklet will take that. Otherwise the url to the file is used to populate the box.
To install the bookmarklet drag this link OPML Auto-discovery Bookmarklet (updated 2006-10-18) to your Bookmarks Toolbar. You can name the bookmarklet as you wish, but I suggest to use "OPML Discoverer". The source code is also available for download as txt files: see the references at the bottom of this post.
The idea for this project came up last Friday in a very inspiring conversation with James Corbett.
I started the IM chat by asking James if he "had a minute", and if he knew of a way to make
hyperlinks to OPML files on anyone’s website to automatically open in
Grazr. After a while it turned out that for months James had been
thinking along slightly different, but converging lines: wouldn’t it be cool if OPML
files could be auto-discovered, similar to what Firefox has been doing
for RSS feeds?
What followed was a lively chat session spread out through the day. James passed on links and code snippets to me, we determined the essential goal of the bookmarklet and then I started to work on the script.
Lately quite a few other people have posted too about their desire to have OPML files auto-discovered, as you can see in this highly relevant, live blog search panel based on a simple Google blog search:
My increased interest in OPML is a natural consequence from my
newsmastering experiments. The biggest boost occurred when I started
developing RSSonate, a list of RSS feeds about RSS technology implemented in Grazr. A few weeks after I started it RSSonate was turned into a BlogBridge expert library. RSSonate is still on live display in the sidebar of CleverClogs, under the heading ‘Others Wrote’.
Note that I didn’t create this bookmarklet from scratch: I adapted
existing source code for a similar bookmarklet made available by
Google—credit to whom credit is due. The Google "Show All Feeds"
bookmarklet was originally announced by Chris Wetherell in the blog
post Subscribing to feeds via little Google buttons
on the Official Google Reader Blog in November 2005. Since then several
others have contributed to the source code, most notably Martin Dittus with Bookmarklet: Display Feed Links on Current Page (March 2006).
My adaptations consist of
showing hyperlinks to OPML files and some cosmetic changes, like
displaying the blue and orange icons and a link back to this CleverClogs post.
Although I do have some programming background, bluntly speaking Javascript programming isn’t my specialty at all. Both James Corbett and I believe there’s room for improvement, so let’s foremost consider this a proof of concept. Hence I kindly invite Javascript programmers
to look at the underlying code and make constructive suggestions for improvements. If you blog about this project, then please send a trackback ping.
Making your site "OPML auto-discoverable"
It’s quite easy to add a link to an OPML file to your website, as long as you have access to your website’s template or source code. Go to the <head> section and insert the following (x)html tag:
<link rel="outline" type="text/x-opml" title="Title of Your OPML File"href="http://www.whatever.com/youropml.opml" />
so, in my case, my site’s source code contains this tag:
<link rel="outline" type="text/x-opml" title="Marjolein’s Writings"href="http://www.blogbridge.com/rl/2417/Marjolein%27s+Writings.opml" />
(Split across lines because of column width)
Update 2006-10-27: By Randy Morin’s request, after a lively discussion over on Tom Raftery’s I.T. views blog between Randy and Tom Morris, I’ve changed the type attribute to "text/x+opml".
Update 2006-10-28: The debate on the proper content of the type attribute isn’t over yet. See James’ Holderness’ contribution over at Randy’s post Understanding Auto-Discovery. Relying on Randy’s good judgment I changed all occurrences of type to "text/x-opml".
Sites that have added an OPML file to their page headers:
Source code links:
OPML Auto-discovery Bookmarklet, formatted source code (updated 2006-10-18 - 11:50 PM)
OPML Auto-discovery Bookmarklet, unformatted source code(updated 2006-10-18 - 11:50 PM)
P.S. The ironic part of this weekend’s marathon project is that I solved a problem that wasn’t my own. Now, is there anyone who knows how to solve my original problem: is it possible to instruct Firefox to display any OPML file using Grazr, in the same way that PDF files are displayed using Adobe Acrobat?
Updates:
2006-10-16, 02:56 AM - TailRank lists all posts linking to this story.
2006-10-16, 10:46 AM - David Rothman submitted a digg about my bookmarklet. If you like, go and cast a vote.
2006-10-16, 10:50 AM - I slightly altered the script so that it only
detects the string "OPML" when it’s at the end of the href attribute.
2006-10-16, 11:28 AM - Sergio Longoni informed me that he is working on a Firefox extension that will display a blue OPML auto-discovery icon in the address bar.
2006-10-16, 11:50 AM - Tom Morris blogs "I’m going to write a PHP API to do similarly on the server side - you
provide a URL and it returns an OPML 2.0 file containing links to all
the OPML and RSS feeds"
2006-10-16, 12:44 PM - It would be great if the search results pages generated by Andy Edmonds’ just released Live Search OPML Generator would also have a <link> tag in their page headers, so that this bookmarklet and other Firefox add-ons can detect them (I tried to post a comment to Andy’s MSDN blog post and to his Surf*Mind*Musings blog post, but they both require that commenters be signed in—too bad, trackbacking instead.)