XML technologies / RSS & Atom / RSS 2.0 / The RSS 2.0 vocabulary / Text or HTML as the content of title and description

(Excerpt from "Newsfeeds with RSS and Atom" by Heinz Wittenbrink, published by Galileo Press, 2005)

The two elements title and description are associated with a fundamental problem of RSS 2.0: its specification does not clearly define whether or how their content may contain markup. Resolving this later became a motivation for Atom.

Handling HTML in RSS became an issue as RSS evolved from syndication to publication. Initially, elements contained only plain text. Soon, titles and descriptions of item elements commonly included HTML markup, sometimes without escaping it through entity references as XML requires. This allows complete HTML fragments in feeds. Aggregators and readers decode them to HTML and use browser-style rendering. Winer does not clearly limit the data types these elements may contain, explicitly permitting only "entity-encoded HTML" inside description.

HTML as RSS content is illegal

One technique is incompatible with XML: HTML must never simply be inserted into RSS elements. Standards-compliant HTML is not well-formed XML unless it is XHTML. XML elements require end tags, identifiers are case-sensitive, attribute values cannot be omitted and must be quoted. HTML markup violates these and other XML rules. A correct XML processor reports an error and stops processing such a document.

Escaping markup

Markup that violates XML rules must be escaped. An XML parser then interprets markup delimiters (English: markup delimiters) as ordinary text. Two techniques achieve this:

  1. A whole text passage can be declared a CDATA section. The characters <, >, & and ;, normally markup delimiters, are treated as "Character Data", the expansion of CDATA. The Infoset extracted by the parser therefore contains only character information. A CDATA section starts with <![CDATA[ and ends with ]]>.

  2. Individual characters can be escaped with entity references, abbreviations representing characters. For example, the character < is represented by the entity reference &lt;, and the character & by &amp;.

The following examples insert HTML into RSS using a CDATA section first, then entity references for individual characters.

<item>
...
   <description><![CDATA[Kostenpflichtige Online-Inhalte werden immer besser angenommen: <blockquote>Die Zeit der Kostenlos-Kultur geht zu Ende, gleichzeitig steigt die Qualität der Angebote</blockquote>, sagt Bernhard Rohleder, Hauptgeschäftsführer von Bitkom...]]></description>
</item>

<item>
...
   <description>Kostenpflichtige Online-Inhalte werden immer besser angenommen: &lt;blockquote&gt;Die Zeit der Kostenlos-Kultur geht zu Ende, gleichzeitig steigt die Qualität der Angebote&lt;/blockquote&gt;, sagt Bernhard Rohleder, Hauptgeschäftsführer von Bitkom...</description>
</item> 

The screenshot shows these examples in NetNewsWire:

Rendering escaped HTML inside description

Figure: rendering escaped HTML inside "description"

All common readers and aggregators support this technique for inserting HTML into a title or description element, without specifying the HTML or XHTML version. Since RSS supports extensions through namespaces, it should be possible to use XHTML with the correct namespace identifier inside an element description. Readers and validators do not support this, however. The RSS specification permits only entity-encoded HTML in its text, but its examples also allow CDATA. Under W3C XML processing rules, the distinction is irrelevant: a parser extracts the Infoset, including which characters occur where. Whether they came from CDATA or entity references is invisible to processing software.

"Escaped Markup Considered Harmful" (Norman Walsh)

Escaping markup for feed software to render as HTML produces syntactically correct XML but violates the format’s guidelines: a string containing escaped delimiters is expected to be interpreted as HTML rather than text. This "hack" encourages software that breaks basic XML processing rules.

This practice has rightly been criticized repeatedly, most clearly by Norman Walsh: if bad examples became the norm, the effort to make XML a universally usable Web markup standard would be wasted.

If HTML content itself quotes markup, already escaped in the "decoded" HTML, processing software has no rule for handling it. In practice, this is solved through double escaping. If the content of description is "Beschreibung des Elements <br/>", it is written as follows:

<description>Beschreibung des Elements &amp;lt;br/&amp;gt;</description> 

If an element description contains a quoted angle bracket, no processing rule applies. For the following content, the processor must "know" that no markup is intended:

<description>URIs werden in wissenschaftlichen Quellenangaben in Spitzklammern gestellt, z. B. so: &lt;http:www.example.com&gt;.</description> 

Unlike RSS 2.0, Atom precisely defines how to embed HTML and XHTML in feeds, though it too cannot entirely avoid escaped markup.

   

 

 

 

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

back to top