6

I've never done it myself, and I've never subscribed to a feed, but it seems that I'm going to have to create one, so I'm wondering. The only way that seems apparent to me is that when the system is updated with a new item (blog post, news item, whatever), a new element should be written to the rss file. Or alternatively have a script that checks for updates to the system a few times a day and writes to the rss file is there is. There's probably a better way of doing it though.

And also, should old elements be removed as new ones are added?

Edit: I should have mentioned, I'm working in PHP, specifically using CodeIgniter, with a mySQL database.

4

8 回答 8

6

对于 PHP,我使用 feedcreator http://feedcreator.org/

<?php define ('CONFIG_SYSTEM_URL','http://www.domain.tld/');

require_once('feedcreator/feedcreator.class.php');

$feedformat='RSS2.0';

header('Content-type: application/xml');

$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = "Item List";
$rss->cssStyleSheet='';
$rss->description = 'this feed';
$rss->link = CONFIG_SYSTEM_URL;
$rss->syndicationURL = CONFIG_SYSTEM_URL.'feed.php';


$articles=new itemList();  // list of stuff
foreach ($articles as $i) {   
    $item = new FeedItem();
    $item->title = sprintf('%s',$i->title);
    $item->link = CONFIG_SYSTEM_URL.'item.php?id='.$i->dbId;
    $item->description = $i->Subject;   
    $item->date = $i->ModifyDate;   
    $item->source = CONFIG_SYSTEM_URL;   
    $item->author = $i->User;
    $rss->addItem($item);
}

print $rss->createFeed($feedformat);
于 2008-11-03T05:28:21.217 回答
4

An RSS Feed is just an XML Document that conforms to a specific schema.

Have a look here

What language are you working in? You can easily script the xml output based on some content in your application. You don't need to explicitly save the file to the file system. It can just be created on the fly

于 2008-11-02T20:57:47.923 回答
3

I'd say the answer is having an RSS feed be nothing more than another view of your data. This means that your rss feed is simply an xml representation of the data in your database. Readers will then be able to hit that specific url and get back the current information in your application.

于 2008-11-02T20:56:45.740 回答
2

我从Magpie RSS得到了很好的结果。设置包含的缓存,您需要做的就是编写查询以检索您的数据并将结果发送到 Magpie RSS,然后由它处理更新频率。

我不会编写 RSS 文件,除非您的服务器负载特别重 - 您只需要一个查询(或添加到数组的一系列查询)来更新内容。编写要按日期排序然后受 X 限制的查询/ies,您也​​不必担心“删除旧东西”。

于 2008-11-02T21:21:13.460 回答
0

这是一个简单的基于 ASP.NET 2 的 RSS 提要,我将其用作本地开发站点的实时书签。可能会帮助您入门:

<%@ Page Language="C#" EnableViewState="false" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.DirectoryServices" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
    System.Collections.Specialized.StringCollection HideSites = new StringCollection();
    System.Collections.Generic.List<string> Sites = new System.Collections.Generic.List<string>();

    HideSites.Add(@"IISHelp");
    HideSites.Add(@"MSMQ");
    HideSites.Add(@"Printers");

    DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/W3SVC/1/ROOT");
    foreach (DirectoryEntry site in entry.Children)
    {
        if (site.SchemaClassName == "IIsWebVirtualDir" && !HideSites.Contains(site.Name))
        {
            Sites.Add(site.Name);
        }
    }

    Sites.Sort();

    Response.Clear();
    Response.ContentType = "text/xml";
    XmlTextWriter RSS = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
    RSS.WriteStartDocument();
    RSS.WriteStartElement("rss");
    RSS.WriteAttributeString("version","2.0");
    RSS.WriteStartElement("channel");
    RSS.WriteElementString("title", "Localhost Websites");
    RSS.WriteElementString("link","http://localhost/sitelist.aspx");
    RSS.WriteElementString("description","localhost websites");

    foreach (string s in Sites)
    {
        RSS.WriteStartElement("item");
        RSS.WriteElementString("title", s);
        RSS.WriteElementString("link", "http://localhost/" + s);
        RSS.WriteEndElement();
    }

    RSS.WriteEndElement();
    RSS.WriteEndElement();
    RSS.WriteEndDocument();
    RSS.Flush();
    RSS.Close();
    Response.End();
}

</script>
于 2008-11-02T21:00:41.957 回答
0

RSS 提要只是以某种方式格式化并从网页链接到的 XML 文档。

看看这个页面(http://cyber.law.harvard.edu/rss/rss.html),它详细介绍了 RSS 规范,提供了示例 RSS 文件供您查看,并向您展示如何从您的地点。

如何创建文档取决于您。您可以在文本编辑器中手动编写它,使用特定于语言的 XML 对象,或者点击 ASPX/PHP/其他页面并发送正确的内容类型标题以及 RSS 文档。

当你开始做这件事时,这并不是那么难。祝你好运!

于 2008-11-02T21:12:44.197 回答
0

有两种方法可以解决这个问题。第一个是根据请求动态创建 RSS 文档。第二种是在发生相关更改时写入静态文件。后者更快,但需要调用来更新(可能)许多地方的提要,而不是一个地方。

使用这两种方法,虽然您可以仅使用更改来编辑文档,但每次使用最新 (10-50) 项重写整个文档要简单得多。

于 2008-11-02T22:00:55.720 回答
0

如果要生成 HTML 中已经存在的元素的提要,一种选择是修改 HTML 标记以使用 hAtom ( http://microformats.org/wiki/hAtom ),然后通过 hAtom->Atom 指向提要阅读器或 hAtom->RSS 代理。

于 2008-11-04T09:59:02.760 回答