djp1988 Posted September 10, 2008 Share Posted September 10, 2008 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 More sharing options...
Ingolme Posted September 10, 2008 Share Posted September 10, 2008 Why would you want to avoid RSS readers? That's the entire point of RSS:You can make a link to your RSS feed from your site, that's all you have to do. Link to comment Share on other sites More sharing options...
djp1988 Posted September 10, 2008 Author Share Posted September 10, 2008 All I want is for people to be able to see the new stuff as a list in the browser bar Link to comment Share on other sites More sharing options...
djp1988 Posted September 10, 2008 Author Share Posted September 10, 2008 is there no step by step short guide to getting this started? step 1: MAKE the documentstep 2: I'm lost now Link to comment Share on other sites More sharing options...
Ingolme Posted September 10, 2008 Share Posted September 10, 2008 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 More sharing options...
djp1988 Posted September 11, 2008 Author Share Posted September 11, 2008 how can I use a for loop in a php document to write the xml document? Because I guess I can't do this directly into the .xml document Link to comment Share on other sites More sharing options...
Ingolme Posted September 11, 2008 Share Posted September 11, 2008 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 More sharing options...
Synook Posted September 12, 2008 Share Posted September 12, 2008 Because I guess I can't do this directly into the .xml documentYou 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 More sharing options...
boen_robot Posted September 12, 2008 Share Posted September 12, 2008 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 hasheader('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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.