如何制作“空"商品? RSS订阅 [英] How to make an "empty" RSS feed

查看:97
本文介绍了如何制作“空"商品? RSS订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是rss提要的新手,但是我能够使用PHP动态创建一个提要,并且效果很好.我的问题是,有时Feed中没有任何物品(我将Feed的使用期限限制为60天,有时那段时间没有任何反应).

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).

我希望发生的是,我只是在xml页面中没有任何<item>.但是,当我以这种方式进行操作时,供稿阅读器(至少是Google的供稿器)似乎有些乏味.即使XML仍正确包含提要的名称,它也将显示为没有标题.

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.

到目前为止,我发现解决此问题的唯一方法是放入一个虚拟物品,即<item><title></title></item>.然后,我的Google阅读器正确地找到了提要的名称,看起来就像一个空白的提要.

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.

是否有一些标准方法来处理空提要的XML表示形式?

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

这是空白Feed的样子

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>

推荐答案

空的提要是没有任何项目的提要附件(通常是XML内容).外壳必须仍然有效,才能成为有效的供稿.

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.

从2003年开始, RSS 2.0规范.

From RSS 2.0 Specification, while from 2003:

一个频道可以包含任意数量的< item> s

A channel may contain any number of <item>s

但是,至少可以从一个RSS XSD 中看到它不兑现,开发人员也知道:

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>

在其他客户中尝试您的供稿.也许这只是google实现的一个怪癖. YMMV.

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

快乐的编码.

有趣的是,请参阅SO问题:

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

这篇关于如何制作“空"商品? RSS订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆