How to make an “empty” RSS feed

倾然丶 夕夏残阳落幕 提交于 2020-02-03 05:21:25

问题


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>

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4009114/how-to-make-an-empty-rss-feed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!