This is a discussion on RSS Syndication - introduction within the PHP Programming forums, part of the Web Development category; hi, i hope that it would be given you the basic idea about RSS What is RSS RSS is a ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi, i hope that it would be given you the basic idea about RSS What is RSS RSS is a Web content syndication format. Its name is an acronym for Really Simple Syndication RSS has become the standard technology for syndicating information to large audiences. Many people have something to say, but its finding the right audience for your voice that matters. A great place to start is by creating your own RSS feed and adding to it as often as you can. An XML-based protocol used to serve news headlines and weblog entries in a streamlined, organized format that lets users subscribe to "feeds" of their favorite content. How Does it Work? Publishers and webmasters provide content and news in an RSS feed. Users view the content of interest in an RSS reader or news aggregator. The aggregator or reader contains the collection of feeds that are of interest to the user. As the RSS feed is updated the content in the reader or aggregator updates with the new information. At any point, users can remove a feed from their aggregator or reader and no longer receive information from that source. Ultimately, the user is choosing the news and content they wish to view. As RSS has increased in popularity more and more webmasters and publishers have adopted RSS as an alternative communication stream. Webmasters use an RSS graphic to indicate the content is available via RSS. In fact, if you look at the bottom of this article, you'll see an XML graphic that will lead you to instructions on adding the headlines of this site to your RSS feed. Websites containing RSS feeds usually have a colorful graphic indicating the availability of an RSS feed. The graphic is usually marked 'RSS' or 'XML'. Simply click the graphic and enter the URL of the file into the reader. Regardless of the RSS reader or news aggregator used by web surfers, the process of adding feeds is generally simple. Web surfers need only to enter the URL of the RSS feed that they wish to view into their news reader. Each time the reader refreshes the feed the information contained within the feed is updated and new content in the feed will appear in the RSS reader. Using PHP to parse RSS RSS is most simply understood as an implementation of XML. It contains (roughly, as versions differ!) the following elements (full specifications can be found at RDF Site Summary (RSS) 1.0 and Page Not Found - Berkman Center for Internet & Society • <title>, the feed title, or the name of the channel. • <description>, a short piece of text describing the feed. • <link>, the URL of the corresponding web page. • <language>, the language used for the content (for more details see RFC1766, Tags for the Identification of Languages. • <lastBuildDate>, the date and time the feed was updated. • <pubDate>, the date and time the content was published. • <copyright>, any copyright information. • <generator>, the software used to generate the RSS. • <docs>, a URL pointing to documentation for the format used in the RSS file (usually one of the specification links above). • <ttl>, time to live, or how long the feed can be cached, in minutes. • <image> An image related to the RSS feed. This in turn contains up to 6 sub-elements, the first three being mandatory: o <title> Same function on the channel's title, and usually contains the same string.• <rating> The PICS rating, originally designed for access control for parents and teachers. See the W3C specification. • <cloud> Specifies a cloud web service which allows notification of updates. • <textInput> Used to specify a text input box, which isn't usually that useful, and we don't look at here. • <skipHours> This tells well-behaved aggregators when not to read the feed, reducing unecessary reads when nothing has changed. It consists of up to 24 <hour> elements, each containing a number from 0 to 23, representing an hour to be skipped. • <skipDays> Similar to <skipHours>, this consists of <day> sub-elements, each listing a day to be skipped (written in full, such as Saturday). • <webmaster> If you enjoy harvesting spam, you may also want to put the email address of the person responsible for technical issues. • <managingEditor> Another spam harvester, this time the email of the editor responsible for the content. • <item> Most importantly, it also contains a number of items, which are usually the articles, stories or posts you're interested in reading. It contains a number of sub-elements, all of which are optional, although one of either title or description must be present. o <title> Usually the article headline.After all that's let's look at a sample, loosely based on that of the PHPBuilder website. For simplicity I've included just two items. It's in RSS 0.91 format. <?xml version="1.0"?> <rss version="0.91"> <channel> <pubDate>Thu, 29 Sep 2005 15:16:13 GMT</pubDate> <description>Newest Articles and How-To's on PHPBuilder.com</description> <link>http://phpbuilder.com</link> <title>PHPBuilder.com New Articles</title> <webMaster>staff@phpbuilder.com</webMaster> <language>en-us</language> <item> <title>In Case You Missed It...The Week of September 26, 2005</title> <link>http://www.phpbuilder.com/columns/weeklyroundup20050926.php3</link> <description>This week Elizabeth brings us news of an upcoming free webcast called Design Patterns in PHP, the schedule for the Fall Zend conference, security alerts for Moveable Type and phpBB, the release of Zend Platform 2, XAMPP for Linux, the latest PEAR/PECL releases and much more! </description> </item> <item> <title>In Case You Missed It...The Week of September 19, 2005</title> <link>http://www.phpbuilder.com/columns/weeklyroundup20050919.php3</link> <description>This week Elizabeth brings us news of the release of PEAR 1.4, Zend Studio 5 Beta, a security vulnerability with PHP-Nuke, the release of a SimpleTest plugin for PHPEclipse, a patch for phpMyAdmin, the latest PEAR/PECL releases and much, much more!</description> </item> </channel> </rss> Save the above xml as a file called phpbuilder.rss, as we're going to use it in the following examples. You can of course use any existing RSS feed out there, but for demonstration purposes it'll be easier if your example is exactly the same as the one I'm using. Let's look at the built-in PHP functions we'll be using. • xml_parser_create() • xml_set_element_handler($xml_resource,$start_eleme nt_function,$end_element_function) • xml_set_character_data_handler($xml_resource,$char acter_data_handler) • xml_parse($xml_resource,$data) The first, xml_parse_create() creates an XML parser and returns a resource handle, used by the other functions. Since an XML feed is made up of a number of elements, and these could differ from feed to feed, we need to apply logic as we traverse through the feed. Elements could contain multiple sub-elements and attributes. To assist with this, the xml_set_element_handler() defines functions to be called dependant on whether an element has opened or closed. It takes three arguments, the first being the XML resource handle returned by xml_parser_create, while the second is is the name of a function automatically called when a new element is reached during parsing, and the third the name of the function automatically called when the end of an element is reached during parsing. (The latter two arguments can also be arrays containing an object name and method reference, which we don't look at here). Calling a function when we reach the start and end of an element is all very well, but we also need to perform some logic when we're actually parsing the characters. xml_set_character_data_handler is the function that determines this. The first of its two arguments is of course the XML resource handle, and the second the name of the function called during parsing. xml_parse() is the function to call to actually start parsing the feed, and takes the XML resource handle as the first argument, and a string containing the portion of the feed as the second. An optional third argument can assist the logic by indicating whether the string is the last piece of data in this parse, but we also don't look at that this time.
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Introduction to ColdFusion | MasterMind | ColdFusion Programming | 6 | 10-04-2008 10:45 PM |
| AJAX introduction | Jeyaseelansarc | PHP Programming | 60 | 04-24-2008 11:21 PM |
| Introduction myself | Bettypeng | Introductions | 3 | 02-10-2008 01:59 AM |
| An Introduction to SAP | Jeyaseelansarc | eCommerce | 1 | 07-18-2007 08:28 AM |
| HTML Introduction | spid4r | HTML, CSS and Javascript Coding Techniques | 0 | 03-08-2007 11:10 PM |