XML technologies / RSS & Atom / Atom / Structure of an Atom feed / Content as a first-class citizen
(Excerpt from "Newsfeeds with RSS and Atom" by Heinz Wittenbrink, published by Galileo Press, 2005)
Text in Atom elements: HTML, XHTML or plain text
The example contains two elements with textual content: title and summary. They contain plain text, but Atom also allows all text-bearing elements to use HTML or XHTML.
Atom calls the content of the elements title and summary "text constructs". (The element content can also contain a text construct; see the section The atom:content element: a content container.) For all such elements, the attribute type identifies the kind of text. Only three values are allowed for type: text, html and xhtml:
If the value is
text, the element contains ordinary text without markup.If the value is
html, it contains text with escaped HTML markup. A passage marked as the HTML elementemwould, for example, be represented as follows:<em> ... </em>. The content is still text, not markup. (In the XML Infoset, only the Unicode character appears.) A client can nevertheless use the escaped markup for presentation. The content must also be valid as the content of an element of typedivin a valid HTML document. Arbitrary fragments are therefore not allowed, ensuring that rendering software can apply HTML rules.The third option is to specify
xhtmlas the value of the attributetypeand use XHTML-marked content. XHTML elements then belong to the Atom document tree as descendants of the text-bearing element. The fragment must not only be valid content for adivelement in a valid XHTML document; it must actually be enclosed in an XHTMLdiv. Clients can interpret the XHTML for display, but unlike HTML content, escaped markup inside the fragment must not be replaced by active markup. This permits quoted markup.
Without a value, content is treated as text. Processing it as HTML or XML therefore requires the attribute type with an appropriate value.
These options support the common practice of including HTML fragments in RSS elements. Since the attribute type clearly identifies the format, processing can respect XML rules. Sam Ruby repeatedly noted that the usual use of "entity-encoded" HTML in RSS does not explain how HTML can be recognised in the first place. In Why We Need Echo, Ben Trott calls content representation a feed’s most important part. It is unclear whether to use double-encoded Entities, a content:encoded element with a CDATA section, or the element xhtml:body. Entity-encoded HTML also leaves handling of relative URIs unclear. Atom uses xml:base to define their interpretation. (For this issue in RSS 2.0 and its predecessors, see also the page Text or HTML as the content of title and description).
The following example shows text constructs of types text and html. In the element summary of the first entry, only the attribute type was added. Processing is identical to the example on the page Basic structure of an Atom document, since software must assume text unless told otherwise. A newsreader could display the second summary element’s content as an HTML element of type P containing a quotation (element type Q).
...
<entry>
<title>Ask Jeeves jetzt auch in Spanien</title>
<summary type="text">Ask Jeeves startete am 5. April mit der Betaversion eines neuen Such-Service...</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 type="html"><P>Kostenpflichtige Online-Inhalte werden immer besser angenommen: <Q>Die Zeit der Kostenlos-Kultur geht zu Ende, gleichzeitig steigt die Qualität der Angebote</Q>, sagt Bernhard Rohleder, Hauptgeschäftsführer von Bitkom. Um 137 Prozent - auf 484 Millionen Euro - werde das Absatzvolumen in diesem Jahr zunehmen. 2004 konnte ein Plus von 105 Prozent verzeichnet werden.</summary>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_02.html</id>
</entry>
...
Code example: text constructs of types text and html
The following example uses XHTML for the second element summary. Note that the namespace is declared as required and the content is enclosed in an XHTML element of type div!
...
<entry>
<title>Bitkom-Studie: Paid Content in Deutschland erfolgreich</title>
<summary type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Kostenpflichtige Online-Inhalte werden immer besser angenommen: <q>Die Zeit der Kostenlos-Kultur geht zu Ende, gleichzeitig steigt die Qualität der Angebote</q>, sagt Bernhard Rohleder, Hauptgeschäftsführer von Bitkom. Um 137 Prozent - auf 484 Millionen Euro - werde das Absatzvolumen in diesem Jahr zunehmen. 2004 konnte ein Plus von 105 Prozent verzeichnet werden.</p>
</div>
</summary>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_02.html</id>
</entry>
Code example: a text construct of type 'xhtml'
Only content explicitly marked XHTML may be parsed as XHTML. This allows potentially dangerous elements, such as JavaScript, to be filtered out.
Quoting markup within XHTML fragments is straightforward, for example:
<atom:title type="xhtml">
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">Das Element <br/>: meist überflüssig!</xhtml:div>
</atom:title>
Code example: quoted markup in an XHTML fragment inside an Atom element
An aggregator treating the content as a valid XHTML fragment can render it correctly as follows:
Das Element <br/>: meist überflüssig!
With HTML text constructs, software decides how to use escaped markup for display. Most aggregators and readers probably interpret escaped delimiters as HTML markup delimiters. The fragment
<atom:title type="html">Das Element <br>: meist überflüssig!</atom:title>
would appear as follows:
Das Element
: meist überflüssig!
If software converts escaped markup only once, quoting markup can use double escaping, as in this fragment:
<atom:title type="html">Das Element &lt;br&gt;: meist überflüssig!</atom:title>
Code example: double-escaped markup in an HTML fragment
The atom:content element: a content container
In Atom, content should have the rights of a "first-class citizen". For this reason, content is a container for any content, beyond the text constructs also allowed in title, subtitle and summary.
content is the most important element in many feeds, making Atom a transport format for diverse content. It probably also has Atom’s most complex content model. The content
may be inside the document (inline) or outside it (out-of-line),
may be textual or binary,
may additionally be described in the element
summaryor not.
These choices are not entirely independent. Out-of-line content, for example, must be described in a summary.
Embedded or linked content
A feed author has two basic options for specifying content for an entry:
Place it directly between the start and end tags of
content; Atom calls this inline content. Unless it is plain text, the attributetypemust identify its type.Supply a URI for retrieving the content as the value of the optional attribute
src. In this case, the content’s MIME media type must be supplied as the value oftype. The specification calls this out-of-line.
These options are mutually exclusive. The attribute src may be used only when content is empty! Both options support textual and binary content, subject to important restrictions described below.
atom:content and atom:summary
The element description is intended in the different RSS standards to summarise the content of an item. In practice it often contains the entire content.
These two uses of description in RSS correspond to two Atom elements: summary and content. The element summary contains an overview, performing the role originally intended for the RSS element description. content holds the content itself rather than descriptions, or links to it.
Either summary or content must occur in an entry element. An entry without its own content must at least describe some content. (The element link usually identifies its location.) More than one element of each type is forbidden, so an entry cannot contain or describe multiple contents. Both types may coexist inside one element entry. The content of summary then describes the content of content.
Two cases require both summary and content:
An element
entrymust also contain an elementsummarywhenever the elementcontenthas the attributesrcand is therefore empty. Content outside the feed must at least be described.summaryis also required when the content ofcontentis Base64-encoded: when its MIME media type does not begin withtextor end withxml.
These requirements follow accessibility principles (accessibility). If content cannot or should not load because of network issues, missing software or security concerns, a description must remain available. Users can also use the description to decide how to handle the content.
Textual content I: plain text, HTML and XHTML
Like the elements title, subtitle and summary, content may contain an Atom text construct: plain text (plain text), HTML or XHTML. As for those elements, the content type is explicitly specified as text, html or xhtml.
The following example places a complete item inside the element content. summary contains a plain-text summary.
...
<entry>
<title>Bitkom-Studie: Paid Content in Deutschland erfolgreich </title>
<summary type="text">Eine neue Studie des Branchenverbands Bitkom ergibt: Paid Content ist inzwischen auch in Deutschland wirtschaftlich erfolgreich.</summary>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<h2>Studie: Kostenpflichtige Online-Inhalte in Deutschland erfolgreich</h2>
<div class="meldung_wrapper">
<p>Das Absatzvolumen von digitalen Inhalten über das Internet werde hierzulande in diesem Jahr um 137 Prozent auf 484 Millionen Euro zulegen. Das meint der Branchenverband <a href="http://www.bitkom.org" target="_blank">Bitkom</a>. Nach einem Plus von 105 Prozent im Jahr 2004 beschleunige sich das Wachstum damit auf sehr hohem Niveau. Bereits in zwei Jahren werde der Markt ein Volumen von deutlich mehr als einer Milliarde Euro erreichen, orakelt der Verband weiter. Bitkom bezieht sich hierbei auf eine aktuelle Studie des European Information Technology Observatory (EITO).</p>
</div>
</div>
</content>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_02.html</id>
</entry>
...
Code example: XHTML as content of content
Textual content II: other text types and XML
content, unlike other Atom text-bearing elements, can contain other text formats with registered MIME media types. This substantially shortened example transmits the previous item in Rich Text Format.
<entry>
<title>Bitkom-Studie: Paid Content in Deutschland erfolgreich</title>
<summary type="text">Eine neue Studie des Branchenverbands Bitkom ergibt: Paid Content ist inzwischen auch in Deutschland wirtschaftlich erfolgreich.</summary>
<content type="text/rtf">
{\rtf1\mac\ansicpg10000\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1031\deflangfe1031 {\upr{\fonttbl{\f0\fnil\fcharset256\fprq2{\*\panose 00020206030504050203}Times New Roman;}
...
{\b\f178\fs48\insrsid873893\charrsid873893
Studie: Kostenpflichtige Online-Inhalte in Deutschland erfolgreich
\par
\par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\f179\fs32\insrsid873893\charrsid873893 Das Absatzvolumen von digitalen Inhalten \u252\'9fber das Internet werde hierzulande in diesem Jahr um 137 Prozent auf 484 Millionen Euro zulegen ... des European Information Technology Observatory (EITO).}{\insrsid14698475
\par }}
</content>
<updated>2005–04–15T08:15:48.428Z</updated>
<id>http://www.celawi.com/webtrends/20040415_02.html</id>
</entry>
Code example: RTF text as content of content
In practice, embedding documents or fragments from other XML vocabularies in the element content is probably more interesting.
XML content has two options:
It can be embedded directly in the element
content. Its root element should then be a descendant ofcontent. XML elements should be placed directly insidecontentwhenever the media type ends in+xml(for exampleapplication/rdf+xml,image/svg+xmlorapplicatiom/xhtml+ xml) or begins withtext(for exampletext/xml). Clients can then pass the data to a specialised application, such as an SVG viewer or an HTML browser.It can be retrieved through a URI supplied as the value of the attribute
src. Use this only if the media type ends in/xml. (For XML media types, see RFC 3023 and XHTML Media Types.application/xmlis a generic media type. Registered types ending in+xml, such asapplication/xhtml+xml, usually have specialised applications.) The data can be downloaded when the appropriate software is available.
The following example shows embedding an SVG graphic in an Atom entry.
...
<entry>
<title>Beispiel einer SVG-Grafik in einem Atom-Feed</title>
<summary type="text">Die Grafik stellt eine Ellipse dar.</summary>
<content type="image/xml+svg">
<svg xmlns="http://www.w3.org/2000/svg" width="12cm" height="12cm" viewBox="0 0 1000 1000">
<path d="M 270,300 A 180, 90 0 0 0 630 300 A 180, 90 0 0 0 270 300" stroke="red" fill="none"/>
</svg>
</content>
<updated>2005–04–15T10:15:02.021Z</updated>
<id>http://www.wittenbrink.net/streams/atom/07_02.html</id>
</entry>
...
Code example: inline XML content in an Atom feed
This opens many possibilities because Atom can transport any XML data, for example directly processing search results received in an OpenSearch fragment (see Amazon’s OpenSearch module).
Binary content
For completeness, the following examples insert binary content inline and out-of-line into an Atom entry. The first uses a file named spacer.gif. As binary content, it must be described in the element summary.
...
<entry>
<title>Beispiel einer base64-kodierten GIF-Grafik in einem Atom-Feed</title>
<summary type="text">Das Element content enthält eine transparente GIF-Datei von einem Pixel Größe.</summary>
<content type="image/gif">R0lGODlhAQABAJH/AP///wAAAMDAwAAAACH5BAEAAAIALAAAAAABAAEAQAICVAEAOw==</content>
<updated>2005–04–15T10:15:02.021Z</updated>
<id>http://www.wittenbrink.net/streams/atom/07_03</id>
</entry>
...
Code example: inline binary content in an Atom entry
The next example links a PDF file out-of-line; the element summary is required here too.
...
<entry>
<title>Fast ein Drittel der amerikanischen MP3-Player-Nutzer nutzt auch Podcasts</title>
<summary type="text">2 Millionen US-Amerikaner haben einen MP3-Player oder einen iPod. 29% davon haben auch schon Podcasts genutzt.</summary>
<content type="application/pdf" src="http://www.celawi.com/webtrends/20050415/pew.pdf"/>
<updated>2005–04–15T10:15:02.021Z</updated>
<id>http://www.wittenbrink.net/streams/atom/07_04</id>
</entry>
...
Code example: a PDF document as out-of-line content in an Atom entry
This form of content in an entry distributes any kind of data or document. Often, however, a link is more appropriate. The next page explains Atom links.
The element enclosure, made famous by podcasting, is therefore unnecessary in Atom. Nevertheless, as a counterpart to the RSS element enclosure, Atom allows a link with enclosure as the value of the attribute rel. This was added late to ensure feature parity with RSS.

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