Atom in a Hurry
For when you need to create a feed in a hurry.
Atom is XML
Which means following a few simple rules to get things working. First there is the XML Header:
<?xml version="1.0" encoding="utf-8"?>
The remainder of the document will lie between <feed>
tags.
<feed xmlns="http://www.w3.org/2005/Atom">
... feed ...
</feed>
The Feed
Each feed needs a title, an id and the date of the last update. The title will be the name of your site:
<title>Acme Industries</title>
In addition, a subtitle can be included as brief description of your site:
<subtitle>Items for everyday purposes.</subtitle>
Author provides a human link to each exerpt. The only required author attribute is a name:
<author><name>Wyle E. Coyote</name></author>
You can also add individual authors within each entry.
The ID needs to be a URI. This can be the root URL of your site:
<id>http://www.acmeindustries.net/</id>
The last update field follows a specific date convention:
<updated>2006-03-14T09:07:05Z</updated>
The ‘Z’ at the end signifies the time is Universal Standard Time. Alternatively, you can add a time zone.
2006-03-14T09:00:00+02:00
2006-01-01T00:00:00-06:00
Though not required, you can add a link field that provides a context for other links in the document. Again, this will be your base URL:
<link href="http://www.acmeindustries.net/" />
And a second link can be added to link to your feed:
<link rel="self" href="http://www.acmeindustries.net/feed.xml" />
There are more fields that can be added, but they can be worked in at a later date.
Entries
The feed can contain any amount of individual entries. Each entry sits between <entry>
tags:
<entry>
... entry ...
</entry>
Each entry also requires a title, an id and the time of last update:
<title>Acme Pen</title>
Each entry id is also a URI. This time, to prevent any potential id conflict, or to survive a reorganisation of your site structure, you can create a TagURI as a permanent id for your document:
First start with the base:
tag:
Then add your domain name:
tag:acmeindustries.net
Then the date of creation (not last update):
tag:acmeindustries.net,2006-03-14
And finally, a short text description. Note, substitute spaces with the ‘plus’ character, and stick to alpha-numeric where possible:
tag:acmeindustries.net,2006-03-14:Acme+Pen
tag:acmeindustries.net,2006-02:Newsletter
tag:acmeindustries.net,2006-03-14:From+Our+CEO
Then the id tags:
<id>tag:acmeindustries.net,2006-03-14:Acme+Pen</id>
The last update field uses the same date format as the feed:
<updated>2006-03-14T09:07:05Z</updated>
A ‘published’ field indicates the original date of publication. This uses the same date format as last update:
<published>2005-11-27T23:55:05Z</published>
Though technically optional, a link is required if you want people to click through to your web site:
<link href="/products/pens/" />
Note that the ‘href’ is relative to your feed link URL.
There are two tags that allow you to include a description of the entry — <content>
and <summary>
. You can use both, either or neither. Each are used the same way:
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
... HTML Content ...
</div>
</content>
<summary type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
... HTML Content ...
</div>
</summary>
Use simple HTML markup, being sure to follow XHTML guidelines:
<p>This is a Paragraph</p>
<h1>This is a heading</h1>
<div><img src="/products/pens/this-pen.jpg" alt="A Pen" /></div>
<ul>
<li>A Bullet</li>
<li>Or Two</li>
</ul>
Atom includes further fields for feeds and entries that give people more information about your site, but these can be explored in more detail.
Implementation
Save your feed using an .xml
extension (e.g. feed.xml) then upload to your site.
On your homepage, and if possible all pages, include this tag within the <head>
tags:
<link rel="alternate" type="application/atom+xml" href="/feed.xml" title="Acme Industries" />
This allows browsers to find your feed, making it available to people who are interested in your site.
Our Feed
Following the above steps, our feed will look like this:
For when you need to create a feed in a hurry.
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Acme Industries</title>
<subtitle>Items for everyday purposes.</subtitle>
<author><name>Wyle E. Coyote</name></author>
<id>http://www.acmeindustries.net/</id>
<updated>2006-03-14T09:07:05Z</updated>
<link href="http://www.acmeindustries.net/" />
<link rel="self" href="http://www.acmeindustries.net/feed.xml" />
<entry>
<title>Acme Pen</title>
<id>tag:acmeindustries.net,2006-03-14:Acme+Pen</id>
<updated>2006-03-14T09:07:05Z</updated>
<published>2005-11-27T23:55:05Z</published>
<link href="/products/pens/" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>This is a Paragraph</p>
<h1>This is a heading</h1>
<div><img src="/products/pens/this-pen.jpg" alt="A Pen" /></div>
<ul>
<li>A Bullet</li>
<li>Or Two</li>
</ul>
</div>
</content>
</entry>
<entry>
... additional entries ...
</entry>
</feed>