6
votes

I'm kind of new to rss feeds, but I'm able to create a feed dynamically using PHP and it works great. My problem is that occasionally the feed doesn't have any items (I limit the age of feed items to 60 days, and sometimes nothing has happened in that time).

What I would expect to happen is that I just simply wouldn't have any <item>s in my xml page. However, when I do it that way, the feed reader (at least the Google one) seems to be a little borked. Even though the XML contains the name of the feed properly still, it shows up without a title.

The only way I've found so far to fix this is to put a dummy item in, that is simply <item><title></title></item>. Then my Google reader finds the name of the feed properly, and it just looks like a blank feed.

It seems that is a hokey solution that is likely incorrect.

Is there some standard way to deal with the XML presentation for an empty feed?

Edit: Here's what the empty feed looks like

<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/">

<channel>

<title>News at Example</title>

<link>http://www.example.com/feed/sample-reviews</link>
<description>Latest Additions to the Sample Category</description>
<dc:language>en-us</dc:language>
<dc:creator>Contact Example through our "contact us" page</dc:creator>

<dc:rights>Copyright 2010 Example Technologies Inc.</dc:rights>
<admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />

        <item><title></title></item>

</channel></rss>
2
Sounds like a bug. There's nothing in principle wrong with an <item>​less feed.bobince
Can you show a full example of your feed?Pekka
I've added it. Without that blank <item><title> tag in there, Google Reader doesn't pick up the main title of the feed for some reason. With it in there, it works fine. And it works fine with actual items as well. Just when there's no item at all am I having a problem.neomech

2 Answers

5
votes

An empty feed is a feed enclosure (the XML stuff generally) without any items. The enclosure must still be valid for it to be a valid feed.

From RSS 2.0 Specification, while from 2003:

A channel may contain any number of <item>s

However, from at least one RSS XSD we can see that it's not honored and the developers know it:

      <xs:element name="item" type="RssItem" minOccurs="1" maxOccurs="unbounded">
         <!-- 
           HACK: According to the RSS 2.0 spec, it should strictly be possible to have zero item elements, 
                 but this makes the schema non-deterministic with regard to extensibility elements
                 so for the moment we undid bug-fix 10231 and set minOccurs=1 to work around this problem. 
         -->
      </xs:element>

Try your feed in different clients. Perhaps it is just a quirk of the google implementation. YMMV.

Happy coding.

Edit: For the fun of it, see the SO question: Where I can find the official XSD schema for RSS 2.0?. It's quite the let-down, actually :-/

11
votes

A feed with zero items is perfectly valid. If Google Reader doesn't handle that properly it should be reported to them as a bug and they should fix it.