XML technologies / RSS & Atom / Atom / Structure of an Atom feed / Basic structure of an Atom document
(Excerpt from "Newsfeeds with RSS and Atom" by Heinz Wittenbrink, published by Galileo Press, 2005)
The following document contains all elements required in every Atom feed, provided it contains any entries:
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Webtrends</title>
<author>
<name>Roswitha Celawi</name>
</author>
<updated>2005–04–15T08:15:48.428Z</updated>
<link rel="alternate" href="http://www.celawi.com/webtrends.html"/>
<entry>
<title>Ask Jeeves jetzt auch in Spanien</title>
<summary>Ask Jeeves startete am 5. April mit der Betaversion eines neuen Such-Service für Spanien. Es ist der erste von mehreren geplanten Starts in Europa dieses Jahr.</summary>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_01.html </id>
</entry>
<entry>
<title>Bitkom-Studie: Paid Content in Deutschland erfolgreich</title>
<summary>Kostenpflichtige Online-Inhalte werden immer besser angenommen: "Die Zeit der Kostenlos-Kultur geht zu Ende, gleichzeitig steigt die Qualität der Angebote", sagt Bernhard Rohleder, Hauptgeschäftsführer von Bitkom.</summary>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_02.html </id>
</entry>
</feed>
Code example: a simple Atom document
The Atom namespace and the xml:lang attribute
Atom documents must declare an explicit namespace. Usually, atom is used as the prefix for the namespace. The Atom 1.0 namespace is identified by the URI "http://www.w3.org/2005/Atom".
Every Atom element may carry the attribute xml:lang, used as defined in the XML specification. (The language tags used to identify languages are listed in RFC 3066.) This attribute can affect processing only for certain elements. The specification explicitly calls these elements "language-sensitive". For all other elements and attributes, language has no effect; for example, no language field needs to be reserved for them in a relational database.
Text, person and date constructs
The specification defines "constructs" (Atom Constructs) for certain combinations of language features that may occur in different positions in an Atom document. This shortens the specification and ensures that the same features have the same meaning regardless of context. The most important and complex construct is called "Text construct". It is introduced on the page about Atom entry content (see Content as a first-class citizen). There are also person and date constructs.
Person constructs describe people, companies and other legal entities. A person construct must contain an element name and may contain elements for an email address and a URI, usually that of the person’s website. They may include further extension elements.
Date constructs specify instants and calendar dates. Elements containing these constructs may have the attributes available to all Atom elements; their content conforms to the XML Schema data type dateTime.
This type is compatible with ISO 8601 and the W3C recommendation on Dates and times.
See also the page Atom constructs in the Atom reference.
feed and entry as structural elements
The following figure shows the structure of the example document:
Figure: structure of a simple Atom document
An Atom document has two hierarchical levels, like the other major newsfeed vocabularies. feed is a feed’s document element. (Atom also permits entry as the document element, but only when updating websites through the Atom API.) feed represents the newsfeed as a whole. Together with the attribute xmlns, it also identifies the document’s vocabulary. It therefore performs the tasks of the RSS document elements rss or RDF and the following element channel or Channel. These and other names no longer preserve RSS compatibility. Atom therefore requires software developed specifically for this format: it is a deliberate new approach rather than another RSS format. The namespace URI also identifies the Atom version; feed therefore needs no attribute version.
feed is a container for a feed’s data and metadata. Descendants of feed include elements describing the feed itself and elements named entry. The entry elements represent the entries belonging to the feed and thus its actual content. (The Atom specification permits feeds without entries, although these are probably rare in practice. There is no upper limit on the number of entries.)
The example contains four elements describing the entire feed: title, author, updated and link. Their English names indicate their meaning:
titlecontains the newsfeed’s title.authorcontains information about the creator.updatedspecifies the last update date.linkpoints to another version of the content.
These four elements are required as descendants of the element feed. Without this information about the feed, an Atom document is invalid!
title and updated must also occur as descendants of entry.
In addition, entry contains the elements:
idwith a URI uniquely identifying the entry, andsummarywith a summary text.
The Atom specification does not prescribe the order of elements inside entry and feed.
An Atom document’s basic structure differs little from the various RSS formats. Element names show the clearest differences: instead of channel there is feed, and instead of item there is entry. The name feed reflects how newsfeeds have become a form of online publication in their own right.
Atom requires more metadata per document than other feed formats, to retain information needed in almost every practical publishing context. (In Building Applications with RSS, Atom and the Atom API, Ben Hammersley describes a "Principle of Conservation of Metadata": "An Atom Document explicitly states the minimum we can know about the resource and no less".)
In particular, the author of an Atom document must always be specified. The element author may be omitted as a descendant of feed only if every individual entry names an author. Institutions may also be specified here. This rule distinguishes Atom from other syndication formats. Its motivation is social rather than technical: someone responsible for every document must be identifiable.
Another important feature of Atom is that every entry must include an element id whose content uniquely identifies the item. Together, the identifier and last-update information allow a newsreader to determine whether an item has already been displayed in its current form.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
