Pete Freitag Pete Freitag

The Proper Content Type for XML Feeds

Updated on November 16, 2023
By Pete Freitag
web

RSS Feeds have a content type problem. Most people end up serving them with the content-type: text/xml. But this practice is frowned upon for several reasons. The main reason people don't like text/xml is because its very vague, there are content types such as application/rss+xml, application/rdf+xml, and application/atom+xml that describe the content of your feed much better than text/xml does. We should be using these types for our feeds.

The problem, however with the more descriptive content types is that Firefox and IE prompt you to download the XML file instead of displaying it in the browser like it would a text/xml document.

download dialog in ie download dialog in Firefox

So what I have decided to do, is to serve the feeds as text/xml if the user agent contains Mozilla. So for IE, Firefox, and Safari 1.x my feed will be served in text/xml other clients will get the proper application/rss+xml MIME type. Here's my code for this:

<cfif cgi.user_agent contains "Mozilla">
	<cfheader name="Content-Type" value="text/xml">
<cfelse>
	<cfheader name="Content-Type" value="application/rss+xml">
</cfif>

I realize that this is not a perfect solution, it may cause browser plugins to have to do some extra work to determine if the document is an RSS, RDF or Atom Feed. Additionally if aggregators are including Mozilla in their user agent, they will get text/xml. But I'm not going to risk loosing potential subscribers over this issue, as some bloggers have reported to be the case when switching.

So I will serve a variable content-type at least until Mozilla bug 256379 is fixed in a production release of FireFox (or if IE beats them I guess :). You can vote for that bug in bugzilla if you find the save dialog to be annoying when you click on RSS feeds.

I also hope that IE7 is will serve the rss related content-types as it would a text/xml doc by default. Scoble, can you make sure IE7 deals with this? (apparently Robert Scoble will read your post if you put his name in it...)

Tim Bray has pointed out why its important for people to get their act together:

  1. To manage the traffic load we're going to have to do some caching. Fortunately, RSS contains some publication and expiry-date data to help intermediate software do this, but to do this it has to recognize the data as RSS and read this stuff. This isn't going to happen until RSS gets served with the proper Media-type.
  2. When someone writes RSS-reader code to live in the Web Browser, it's going to need a consistent Media-type to be able to recognize RSS.

Yet Another Community System cites some of the problems with text/xml such as the character set issues:

The default character set, which must be assumed in the absence of a charset parameter, is US-ASCII or ISO-8859-1 for all MIME types prefixed by text, depending of the Request for Comment you are considering. Of course, having two different specifications is confusing to the software industry. But also, no one of these two charsets can support complex foreign charsets as those used in Asia. On the other hand, implementors and users of XML parsers tend to assume that the default charset is provided by the XML encoding declaration or BOM.


rss xml atom rdf content-type http mime firefox ie mozilla

The Proper Content Type for XML Feeds was first published on June 13, 2005.

If you like reading about rss, xml, atom, rdf, content-type, http, mime, firefox, ie, or mozilla then you might also like:

Discuss / Follow me on Twitter ↯

Comments

I disagree... There's a XML schema and/or DTD associated with the document. An RSS-capable browser should be capable of recognizing RSS, RDF or ATOM data based on that. Likewise, the XML encoding marker or BOM is sufficient for determining whether RSS is properly formatted or not.

Why should it be necessary to specify new, incompatible MIME types to solve problems that have already been solved within the XML files?
by Adam Ness on 06/13/2005 at 3:46:00 PM UTC
Adam, Where I see the benefits of a new media type is for http middleware such as caching, or proxies. If they can quickly determine the type of document from its headers with out actually inspecting or parsing it, this is good for performance. So having mime types for RSS, RDF, and ATOM would improve performance of the applications that use them.

I agree however that we shouldn't be declaring new MIME types for every possible variant of XML. But RSS, RDF, and ATOM are quite popular, and I think that justifies creating having a new mime type.
by Pete Freitag on 06/13/2005 at 4:06:47 PM UTC
HTTP already has fairly extensive and powerful cache management headers in existence. I don't think that having a different set of cache rules for syndication content is necessarily a good idea, but I can see that there might be some desire for the flexibility in rare cases.
by Adam Ness on 06/13/2005 at 4:11:54 PM UTC
RSS does allow for caching features that are not available in HTTP caching, such as SkipDays or SkipHours. If your only updating a feed during business hours, then its handy to specify that its not going to change at night or on the weekend.

Caching is very important for RSS, because ask they require a lot of bandwidth. My RSS feed gets more than 8 times as many hits as my home page. RSS use is only going to grow in the coming years.

Adam, what disadvantages are there to adding these MIME types?
by Pete Freitag on 06/13/2005 at 4:26:28 PM UTC
SkipDays and SkipHours can easily be represented by sending the appropriate "Expires" header on your RSS. e.g. If you don't update on the weekend, just set your Expires header to Monday Morning.

Additionally, the SkipDays and SkipHours information is embedded in the RSS file itself, which means your cacheing server must be parsing the XML data. If it is, then it can recognize the DTD or Schema information just as easily as it can recognize the SkipDays/SkipHours information.

The disadvantages to registering additional MIME types are multiple: Crowding of the MIME namespace, competing standards (Is it application/rss+xml or x-application/rss or text/rss, or text/rss-xml?) Duplication of existing functionality, Incompatibility with browsers such as IE and Mozilla which don't know the MIME type that you're talking about, inability to pass the data through certain types of filtering firewalls/proxies, incompatibility with some fully standards compliant xmlhttp libraries which expect results in text/xml, and a variety of others. I don't see the benefits outweighing the negatives.
by Adam Ness on 06/13/2005 at 5:26:51 PM UTC
Good points Adam, I suppose you could indeed implement SkipHours and SkipDays like functionality with HTTP caching. It would be a bit more difficult however.

Also the caching server would only have to parse the XML if it matched the RSS mime type, that's why I state that as an advantage. With just a text/xml mime type you would have to check every XML document served.
by Pete Freitag on 06/13/2005 at 5:39:46 PM UTC
Adam: The ship has already sailed. application/atom+xml is being built into Apache, application/rss+xml is already a "running code" standard, and that's that.

Secondly, you won't find much of anyone associating DTDs or schemas with syndication files. There will be a non-normative RelaxNG schema for Atom, but everyone will ignore it.
by Roger Benningfield on 06/14/2005 at 2:55:44 PM UTC
IMHO, browsers should not display angled brackets. When you click on an application/rss+xml file, the reference should be passed to your RSS reader and you should be prompt to subscribe. It's called 'Universal Subscription Mechanism'.
by Randy Charles Morin on 06/27/2005 at 11:21:50 PM UTC
Politics aside. After reading the spec and the w3c recomendation on Content Type declaration in rss (and likes), i was strugling to figure out what was going on (with firefox behaviour). Now i've implemented this hack in my Zope server and so far so good. Thanks.
by Bricolage on 01/24/2006 at 7:00:23 PM UTC
I would be interested to see an example of how the DTML/TAL looks for a Zope version of this.
by clint on 02/14/2006 at 11:44:35 AM UTC
From a ColdFusion perspective, is there any difference between
cfcontent type="text/xml"
and
cfheader name="Content-Type" value="text/xml"

Thanks.
by Jean Moniatte on 03/18/2006 at 6:10:05 PM UTC
This may sound stupid, but as someone who hasn't kept up much I've been a little curious:

HTML - text/html
XML - text/xml
XHTML?
application/html+xml
Why application? RSS and Atom do it too, as you've written in your post. But I haven't seen Why explained on any site...
by Keilaron on 06/21/2007 at 12:36:17 PM UTC
Hai,
my rss contains error i not able to find where is the error anyone know please find .

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Radiant : upto-250000</title>
<link>http://www.property.com</link>
<description>Latest Properties upto-250000</description>
<language>en-gb</language>

<copyright>Copyright 2007, Properties Ltd.</copyright>
<pubDate>Mon, 39 Oct 2007 7:39:07</pubDate>
<lastBuildDate>Mon, 39 Oct 2007 7:39:07</lastBuildDate>
<image>
<title>Radiant</title>
<url>http://www.property.com/mortgage/images/logo.jpg</url>
<link>http://www.property.com</link>

</image>
<item>
<title>&#163;25000 Lorem ipsum, Lorem ipsum</title>
<link>http://www.property.com/mortgage/index.php?option=rssdet&amp;id=2&amp;type=1&amp;range=1</link>
<description><![CDATA[ <img src="http://www.property.com/mortgage/rss/img1/2.jpg" width="102" height="78" /> Lorem ipsum <br><br> ]]></description>
<pubDate>Mon, 39 Oct 2007 7:39:07</pubDate>

</item>
</channel>
</rss>
by Rajapandian on 10/29/2007 at 12:42:39 AM UTC
hello, recently I'm learning about ajax + asp.net 2.0,
and now, I want to make a ajax rss reader,
and problems appear when I try to get rss data from rss feed url with javascript, like
http://rss.sina.com.cn/finance/gjcj.xml
my code to do that is like

rssReqXml = getXmlDoc();
rssReqXml.onreadystatechange=viewContent;
rssReqXml.open("GET", escape(url),true);
rssReqXml.send( null);

and I always get some response message saying "bad request",
it doesn't work even when I set the contenttype to text/xml,
so, what do think might be the problem,
and how to make work,
thank you
by Adun on 12/18/2007 at 1:36:47 PM UTC
Peter--

Thanks for posting this. After adding this to the top of my cfm file, my feed validates with http://feedvalidator.org.
by Kenneth Rainey on 02/14/2008 at 6:50:53 AM UTC
Hi, can any one guide me, i have created an rss feed, which displays perfectly in text/xml content type, but on application/rss+xml or application/atom+xml it does not display any thing in my browser, what would be the problem. i am not able to directly click and subscribe to the created rss feed using outlook.
by Milan on 05/21/2009 at 7:31:43 PM UTC
Content-Type is usually what's written, but in reality HTTP headers are case-insensitive.
by Keilaron on 07/02/2010 at 12:27:41 AM UTC