RSS Atom Example

Xah Lee, 2006-09

There is a web syndication format standard called Atom. In this page, i show a simple example of this format.

For some background and detailed info about Atom, see Wikipedia: Atom (standard)↗

Now, here's a Atom sample template:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="http://xahlee.org/Periodic_dosage_dir/">

 <title>Xah's Periodic Dosage</title>
 <subtitle>Ethnology, Ethology, and Tech Geeking</subtitle>
 <link rel="self" href="http://xahlee.org/Periodic_dosage_dir/pd.xml"/>
 <link rel="alternate" href="http://xahlee.org/Periodic_dosage_dir/pd.html"/>
 <updated>2006-09-11T02:35:33-07:00</updated>
 <author>
   <name>Xah Lee</name>
   <uri>http://xahlee.org/</uri>
 </author>
 <id>http://xahlee.org/Periodic_dosage_dir/pd.html</id>
 <icon>http://xahlee.org/siteicon.png</icon>
 <rights>© 2006 Xah Lee</rights>

 <entry>
   <title>Wikipedia readings: keyboards ...</title>
   <id>tag:xahlee.org,2006-09-09:015218</id>
   <updated>2006-09-08T18:52:18-07:00</updated>
   <summary>Wikipedia readings ...</summary>
   <content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Wikipedia readings</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard">http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard</a></li>
<li><a href="http://en.wikipedia.org/wiki/Lisp_programming_language">http://en.wikipedia.org/wiki/Lisp_programming_language</a></li>
<li><a href="http://en.wikipedia.org/wiki/Emacs">http://en.wikipedia.org/wiki/Emacs</a></li>
</ul>
</div>
   </content>
  <link rel="alternate" href="pd.html"/>
 </entry>
</feed>

You can use the above as a template. The file name should have a suffix of “.xml” or “.atom”. The MIME type should be “application/rss+xml xml”.

Few things of note:

The «link ref="self" ...» should point to the url of the file itself. The «link ref="alternate" ...» should be the html url for this feed.

Note the date format. It must strictly be of this form: “yyyy-mm-ddThh:mm:ss±hh:mm”. The T in the middle is literal. It is used as a separator of date and time. The last part “±hh:mm” is your local time offsite to GMT.

Now, in the «entry» section, the «content» is optional. The «link ref="alternate"» should be the html path of the full article.

The «id» tag is very important. It needs to be unique and unchanging across ALL atom entries in the universe, and it must be in a uri format. What i've done here, and you can follow, is this format: «tag:xahlee.org,2006-09-09:015218». Namely, “tag:”, then your domain name, a comma, then a date string yyyy-mm-dd, then a colon, then unix epoch seconds. If two entry might be made in the same second in a large organization, then you might also want to add author name.

To validate your atom page, goto http://feedvalidator.org/

For a full tutorial, goto http://www.atomenabled.org/developers/syndication/

For the complete spec, goto http://tools.ietf.org/html/rfc4287

For a sample valid atom.xml, goto http://xahlee.org/Periodic_dosage_dir/pd.xml


If you use emacs, the following functions can be useful. It defines several function to let you insert date-time, or the atom id, or a entry template.

(defun dt () "insert current date-time string." (interactive)
  (insert
   (concat
    (format-time-string "%Y-%m-%dT%T")
    ((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5))) (format-time-string "%z"))
    )
   )
  )
; generate rss atom's id. e.g. tag:xahlee.org,2006-08-08:053432
(defun atom-id () "insert a tag-uri for Atom rss." (interactive)
  (insert (format-time-string "tag:xahlee.org,%Y-%m-%d:%H%M%S" (current-time) 1)))
;(insert (format "%s" (random))) number-to-string

(defun atom-entry () "insert a blank Atom rss entry template." (interactive)
(insert (concat
" <entry>
   <title>t</title>
   <id>"
(format-time-string "tag:xahlee.org,%Y-%m-%d:%H%M%S" (current-time) 1)
"</id>
   <updated>"
(concat
    (format-time-string "%Y-%m-%dT%T")
    ((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5))) (format-time-string "%z"))
    )
"</updated>
   <summary>tt</summary>
   <content type=\"xhtml\">
<div xmlns=\"http://www.w3.org/1999/xhtml\">
</div>
   </content>
  <link rel=\"alternate\" href=\"pd.html\"/>
 </entry>"
))
)

For more detail about emacs, see emacs+elisp tutorial


2006-09-11

i just discovered bugs in rss aggregator in google.com, my.yahoo.com, my.msn.com .

For my.msn.com, it won't understand validated atom 1.

For google.com, it won't understand relative links unless you have xml:base in your atom.xml.

For yahoo.com, it won't understand relative links, period, regardless whether you have xml:base.

According to the Atom spec http://tools.ietf.org/html/rfc4287 on relative links which defers to http://tools.ietf.org/html/rfc3986#section-5.1.1, a atom doc without explicit xml:base should take the base as the path the doc is gotton. (just as with html files)

So, it seems to me google's behavior is wrong.


Page created: 2006-09.
© 2006 by Xah Lee.
Xah Signet