Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

RSS Tutorial


RSS Tutorial

By mido avatarmido | 7401 Reads |
0     0

Hi people, its my first article here… About RSS

In recent time the web 2.0 has widely spread over most of the web sites

For more information about Web2.0

Web 2.0

RSS Tutorial:

–Before you read this article, you should have a basic understanding of :

  • XHTML
  • XML

Some tips: > RSS stands for Really Simple Syndication > RSS defines an easy way to share the news of the website e.g http://hellboundhackers.org/news/rss.xml

> RSS is written in XML. > RSS Files can be easily updated. > RSS file must have an .xml extension. > RSS data is simple and doesn't cost much bandwidth :P 1.RSS intro:

  RSS was designed to veiw contents, if youve a website, a news section in that website, (if you have no RSS feed in it) visitors will have to visit it daily to see what has been updated...

There are several versions of RSS

Heres the history of the RSS taken from http://w3schools.com/rss/rss_history.asp

  • 1997 - Dave Winer develops scripting News. RSS was born.
* 1999 - Netscape develops RSS 0.90 (which supported scriptingNews). This was simply XML with an RDF Header.
   
* 1999 - Dave Winer at UserLand develops scriptingNews 2.0b1 (This included Netscape's RSS 0.90 features)
   
* 1999 - Netscape develops RSS 0.91. In this version they removed the RDF header, but included most features from scriptingNews 2.0b1.
   
* 1999 - UserLand gets rid of scriptingNews and uses only RSS 0.91
   
* Netscape stops their RSS development
   
* 2000 - UserLand releases the official RSS 0.91 specification
   
* 2000 - A group lead by Rael Dornfest at O'Reilly develops RSS 1.0. This format uses RDF and namespaces. This version is often confused as being a new version of 0.91, but this is a completely new format with no ties to RSS 0.91
   
* 2000 - Dave Winer at UserLand develops RSS 0.92
   
* 2002 - Dave Winer develops RSS 2.0 after leaving Userland
   
* 2003 - The official RSS 2.0 specification is released

Actually, theres no standard version, many sites use RSS 0.91, 1.0, 0.9x

2.RSS Syntax:

  This is a simple RSS document:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
 <title>HBH</title>
 <link>http://hellboundhackers.com/</link>
  <description>Learn to secure your website...</description>
  <item>
    <title>HBH con</title>
    <link>http://hellboundhackers.com/hbhcon.php</link>
    <description>Come on and buy tickets !</description>
  </item>
  <item>
    <title>New SQL injection</title>
    <link>http://hellboundhackers.com/news/link_to_the_news_page</link>
    <description>New SQL Injection discovered, its extreeemly dangrous</description>
  </item>
</channel>

</rss>

–first line of the document is the XML version declaration. –Second line defines the RSS version (here we've used version "2.0") –XML tag has no end tag…e.g (<?xml version="1.0" encoding="ISO-8859-1" ?></xml> <<Wrong) (<?xml version="1.0" encoding="ISO-8859-1" ?> <<Right) Next line contains the <channel> element. This element is used to describe the RSS feed.

3.Elements Description :

   &lt;channel&gt; element contains one or more of &lt;items&gt; (like the flat which has some rooms)

Element Description

<category> Optional. Defines one or more categories for the feed

<cloud> Optional. Register processes to be notified immediately of updates of the feed

<copyright> Optional. Notifies about copyrighted material

<description> Required. Describes the channel

<docs> Optional. Specifies an URL to the documentation of the format used in the feed

<generator> Optional. Specifies the program used to generate the feed

<image> Optional. Allows an image to be displayed when aggregators present a feed

<language> Optional. Specifies the language the feed is written in

<lastBuildDate> Optional. Defines the last-modified date of the content of the feed

<link> Required. Defines the hyperlink to the channel

<managingEditor> Optional. Defines the e-mail address to the editor of the content of the feed

<pubDate> Optional. Defines the last publication date for the content of the feed

<rating> Optional. The PICS rating of the feed

<skipDays> Optional. Specifies the days where aggregators should skip updating the feed

<skipHours> Optional. Specifies the hours where aggregators should skip updating the feed

<textInput> Optional. Specifies a text input field that should be displayed with the feed

<title> Required. Defines the title of the channel

<ttl> Optional. Specifies the number of minutes the feed can stay cached before refreshing it from the source

<webMaster> Optional. Defines the e-mail address to the webmaster of the feed

	RSS &lt;item&gt; Element

Element Description

<author> Optional. Specifies the e-mail address to the author of the item

<category> Optional. Defines one or more categories the item belongs to

<comments> Optional. Allows an item to link to comments about that item

<description> Required. Describes the item

<enclosure> Optional. Allows a media file to be included with the item

<guid> Optional. Defines a unique identifier for the item

<link> Required. Defines the hyperlink to the item

<pubDate> Optional. Defines the last-publication date for the item

<source> Optional. Specifies a third-party source for the item

<title> Required. Defines the title of the item

<item>: Each <item> considered a pack that contains some news…

It contains child elements which are:

<title>, <item>, <link> and <describtion> are the basics

>><title> : is the title for the news (e.g) "HBH Con"

>><link> : is the link to the item, like : http://hellboundhackers.org/hbhcon.php

>><description> : Describes what the <item> tells, considered the news (story)

4.RSS Readers:

 Note: Firefox has a built-in rss reader, for example if youre in a website offers  RSS feeds, you will see an RSS icon beside teh URL

You can write your own RSS feed reader with different ways (PHP (preg_match), Javascript(getElementByTagName), or AJAX)

Simple RSS Reader with PHP(preg_match):

<?php

function display_feed($url, $num=5, $template= "<div id=\"feeditem\"><a href=\"#link#\"> #title#</a><br />#description#</div>") {

if ($rss=@file_get_contents($url)){

$rss=xml2array($rss); if (is_array($rss)){ $code=""; $count=0; foreach($rss['rss'][0]['channel'][0]['item'] as $val){ $tpl=$template; foreach($val as $key=>$val2) { $val2=html_entity_decode(htmlentities(strip_tags($val2))); $tpl=str_replace("#".strtolower($key)."#", $val2, $tpl);

  }

if ($count<$num) $code.=$tpl; ++$count; } }else{ return FALSE; } echo $code; return TRUE; }else{ return FALSE; } } function xml2array($text) {

$reg_exp = &#39;/&lt;(&#92;w+)[^&gt;]*&gt;(.*?)&lt;&#92;/&#92;&#92;1&gt;/s&#39;;
preg_match_all($reg_exp, $text, $match);
		foreach ($match[1] as $key=&gt;$val)
 {
   if (preg_match($reg_exp, $match[2][$key]) )
             
	{

       		$array[$val][] = xml2array($match[2][$key]);
   
} 	

else {

             $array[$val] = $match[2][$key];
 
  }

}

return $array;

}

display_feed("http://www.hellboundhackers.org/news/rss.xml", 10);

?>

That was a simple RSS Reader (by PHP) for Hellboundhackers.org, simpily, it grabs each tag(<item>, <title>, <link> and<description>) and echo them out…

For AJAX:

Actually, AJAX is a big field that deserves a separated article :-). But, this is a very good AJAX RSS reader (dragable boxes) http://www.dhtmlgoodies.com/index.html?whichScript=dragable-boxes ** You can find more and more scripts for AJAX here : http://www.dhtmlgoodies.com/index.html?page=ajax **

5.RSS References:

a) Thanks for W3Schools.com my reference for ever :p b) php.net PHP for ever!! c) wikipedia.org….hmmm? everything you needed over there…

Comments
richohealey's avatar
richohealey 17 years ago

WHOA… like.. whoa… this is awesome, i suggested that you expand a little, this is fantasic. Next time someone asks about RSS i'm definately linking them here.

mido's avatar
mido 17 years ago

WOOHOO, Thanks richo for Appreciation :D

ghost's avatar
ghost 17 years ago

great article:D

ghost's avatar
ghost 17 years ago

10/10, quality!

mido's avatar
mido 17 years ago

Thanks guys for reading and rating :) Hope the article was useful…

ghost's avatar
ghost 17 years ago

FUCKING CITE FUCKING YOUR FUCKING FUCKING FUCKING SOURCES FUCKING YOU FUCKING FUCKING FUCKING etc… http://php.digipedia.pl/php/manual/pl/ref.xml.php

SySTeM's avatar
SySTeM 17 years ago

Wow, you basically just done "Other 13" for everyone, good work

ghost's avatar
ghost 17 years ago

–XML tag has no end tag…

Actually it does, the ?> on the end is the closing tag (same as in PHP)

mido's avatar
mido 17 years ago

@mastergamer: hmmm, i meant that its not like <rss..>which has another </rss>

spyware's avatar
spyware 17 years ago

Worst RSS & XML editor ever. I see no mention about the use of XML in other applications and the fact that the programming language itself is useless without interpreter. Basically you just copied some information off the web and pasted it all in one document. Maybe you can get away with this style of work at your school but I don't like it at all. Rating "avarage" for an avarage article.

spyware's avatar
spyware 17 years ago

*editor = article. Don't ask, my mind is messed up.

mido's avatar
mido 17 years ago

Thanks all…

Apollo_15's avatar
Apollo_15 16 years ago

great article ;)