How to create an empty RSS feed

I'm a little new to rss feeds, but I can dynamically create a feed using PHP, and it works great. My problem is that sometimes the feed has no items (I limit the age of the feed to 60 days, and sometimes nothing happened during this time).

What I would expect is that I simply would not have an <item> in my xml page. However, when I do this, the feed reader (at least one Google) seems a bit worried. Although the XML correctly contains the name of the feed, it is displayed without a title.

The only way I have found so far to fix this is to introduce a dummy element, i.e. just <item><title></title></item> . Then my Google reader finds the feed name correctly and it just looks like an empty channel.

This seems to be a hockey decision, which is probably incorrect.

Is there any standard way to work with an XML representation for an empty feed?

Edit: here, that empty thread 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> 
+6
xml php rss feeds
source share
2 answers

An empty feed is a feed hull (usually XML material) without any elements. The enclosure must be valid in order for it to be a valid feed.

From Specification RSS 2.0 , and since 2003:

A channel can contain any number of <item> s

However, at least one XSD RSS , we can see that it is not respected, and developers know this:

  <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 the feed from different customers. Perhaps this is just a fad of Google's implementation. YMMV.

Happy coding.

Edit: For fun, see question SO: Where can I find the official XSD scheme for RSS 2.0? . This is quite amenable, in fact: - /

+5
source share

Serving with zero positions is perfectly acceptable. If Google Reader does not handle this properly, it should be reported to them as an error, and they should fix it.

+10
source share

All Articles