How do you create an RSS feed?

I never did this myself, and I never subscribed to the feed, but it seems to me that I need to create it, so I'm interested. The only way that seems obvious to me is that when the system is updated with a new element (blog post, news item, whatever), the new element must be written to the rss file. Or, alternatively, there is a script that checks for updates to the system several times a day and writes it to an rss file. There is probably a better way to do this.

And also, if old items are deleted as new ones are added?

Change I should have mentioned, I work in PHP, in particular using CodeIgniter, with mySQL database.

+6
php rss
source share
8 answers

For PHP, I use 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); 
+6
source share

I would say that the response to the RSS feed is nothing but a different look at your data. This means that your rss feed is just an XML representation of the data in your database. Readers can then hit this specific URL and return the current information to your application.

+3
source share

An RSS feed is just an XML document that conforms to a specific schema.

Look here

What language do you work in? You can easily output xml script based on some content in your application. You do not need to explicitly save the file in the file system. You can simply create it on the fly.

+3
source share

I have good results from Magpie RSS . Set up enabled caching, and all you have to do is write a request to retrieve your data and send the result to Magpie RSS, which then processes the update frequency.

I would not write an RSS file if your server is not in a particularly heavy load - you only need one request (or a series of requests added to the array) for updated materials. Write a query (s) that will be sorted by date, and then limited to X, and you won’t need to worry about “deleting old stuff”.

+2
source share

Here is a simple ASP.NET 2-based RSS feed that I use as a live bookmark for my localhost development sites. May help you get started:

 <%@ 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> 
0
source share

An RSS feed is only an XML document formatted in a specific way and linked to a web page.

Take a look at this page ( http://cyber.law.harvard.edu/rss/rss.html ), which details the RSS specification, provides an example RSS file for you to view and shows how to link them to your site.

How you create the document is up to you. You can write it manually in a text editor, use a language-specific XML object, or click on the ASPX / PHP / other page and send the correct content headers along with the RSS document.

Not everything is so complicated when you start it. good luck!

0
source share

There are two ways to approach this. First, dynamically create an RSS document upon request. Secondly, to write to a static file when a corresponding change occurs. The latter works faster, but requires a call to update the feed (probably) in many places and in only one.

Using both methods, although you can only edit the document with changes, it is much easier to simply rewrite the entire document each time using the most recent (10-50) elements.

0
source share

If you want to create a feed of elements that already exist in HTML, one option is to change your HTML markup to use hAtom ( http://microformats.org/wiki/hAtom ), and then read feeds through hAtom-> Atom or hAtom-> RSS proxy.

0
source share

All Articles