The Proper Content Type for XML Feeds
By Pete Freitag
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.
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:
- 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.
- 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.
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:
- Foundeo's 2007 End of the Year Sale
- SoloSub is for button overload
- Finding Feed subscribers from the User Agent
- One liner to download a Browser with PowerShell on Windows Server
Discuss / Follow me on Twitter ↯
Tweet Follow @pfreitagComments
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.
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?
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.
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.
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.
cfcontent type="text/xml"
and
cfheader name="Content-Type" value="text/xml"
Thanks.
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...
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>£25000 Lorem ipsum, Lorem ipsum</title>
<link>http://www.property.com/mortgage/index.php?option=rssdet&id=2&type=1&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>
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
Thanks for posting this. After adding this to the top of my cfm file, my feed validates with http://feedvalidator.org.
Why should it be necessary to specify new, incompatible MIME types to solve problems that have already been solved within the XML files?