tags:

views:

56

answers:

2

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/"&gt;

<channel>

<title>News at Example</title>

<link>http://www.example.com/feed/sample-reviews&lt;/link&gt;
<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>
+3  A: 

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 :-/

pst
I've seen some discussions online about setting up some sort of "default" item that indicates that there are no feed items at this time. Does it make sense to set up an item like that given the issue with not having any?
neomech
@neomech Use whatever works [best] for the given client(s). Happy coding.
pst
+4  A: 

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.

Dave Winer
I agree with that. That said, lots of people use Google Reader (myself included!) and I'd like to get my code working properly in the meantime so any users I have who are using Google at least see what they're supposed to. Sounds like having a "hack" of some sort for an empty feed is the way to go.
neomech