Jump to content

rss question


djp1988

Recommended Posts

I have done an rss document named rsstest.xml and I have included it in my page by adding:

<link href="rsstest.xml" rel="alternate" type="application/rss+xml" title="Sitewide RSS Feed" />

But noz I don't knoz what to do, I have read alot but don't understand how to make this a working rss, what's the next step? I wish for this to stay totally independant of other sites, so I want to avoid "rss readers" I'm probably talking rubbish now, I really don't understand the next step, I have read the tutorial and everything... help me please

Link to comment
Share on other sites

Usually, you want the RSS document to update when you post a new news article on your site. I use PHP's file_put_contents() and DOM library in my own custom made content managing system to do that.If you have an RSS file on your site already, there's not a lot you have to do. Link to it from your page and users will be able to add it to their list of feeds.

<a href="rsstest.xml">RSS feed</a>

Link to comment
Share on other sites

Here's how I usually modify my XML files with PHP:

$xmlDoc = new DOMDocument();$xmlDoc->load("file.xml");// Add <node>Some text</node> to the end of the XML document$newNode = $xmlDoc->createElement("node");$newNodeText = $xmlDoc->createTextNode("Some text");$newNode->appendChild($newNodeText);$xmlDoc->documentElement->appendChild($newNode);// Save the XML documentfile_put_contents("file.xml",$xmlDoc->saveXML());

Link to comment
Share on other sites

Because I guess I can't do this directly into the .xml document
You can set the PHP interpreter to process .xml documents, or use URL rewriting to rewrite, say, feed.php into feed.xml.
Link to comment
Share on other sites

You can set the PHP interpreter to process .xml documents, or use URL rewriting to rewrite, say, feed.php into feed.xml.
Technically speaking, there's no need for URL rewriting. As long as PHP has
header('Content-type: application/xml');

or maybe

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

any RSS reader will be able to read the feed.Following Ingolme's example, here's a more complete way to update an XML (and an RSS 2.0 feed in particular):

/* Set up the stage.Instead of entering these directly, you should accept them by a form.Ideally, validate them and filter them. */$file = 'file.xml';$newTitle = 'This is a new article';$newLink = 'http://example.com/article.html';$newDescription = 'A very cool new article';//Open the XML document$xmlDoc = new DOMDocument();$xmlDoc->load($file);//Create the elements that make an item.$title = $xmlDoc->createElement('title', $newTitle);$link = $xmlDoc->createElement('link, $newLink);$description = $xmlDoc->createElement('description', $newDescription);//Create a new item element, and add the rest to it.$item = $xmlDoc->createElement('item');$item->appendChild($title);$item->appendChild($link);$item->appendChild($description);//Append the new item to the first channel of the feed.$xmlDoc->documentElement->childNodes->item(0)->appendChild($item);/* If you want, you can instead make the new item appear at the top of the list. Commend out the line above, and uncomment the ones below to do that. *//*$items = $xmlDoc->documentElement->childNodes->item(0);if ($items->childNodes->length === 0) $items->appendChild($item) else $items->insertBefore($item, $items->childNodes->item(0));*/// Save the XML document$xmlDoc->save($file);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...