CHAPTER 20 WEB SERVICES MagpieRSS MagpieRSS (Magpie (Web server on xp)
CHAPTER 20 WEB SERVICES MagpieRSS MagpieRSS (Magpie for short) is a powerful RSS parser written in PHP by Kellan Elliott-McCrea. It s freely available for download via http://magpierss.sourceforge.net/ and is distributed under the GPL license. Magpie offers developers an amazingly practical and easy means for retrieving and rendering RSS feeds, as you ll soon see. In addition, Magpie offers users a number of cool features, including: Simplicity: Magpie gets the job done with a minimum of effort by the developer. For example, typing a few lines of code is all it takes to begin retrieving, parsing, and converting RSS feeds into an easily readable format. Nonvalidating: If the feed is well formed, Magpie will successfully parse it. This means that it supports all tag sets found within the various RSS versions, as well as your own custom tags. Bandwidth-friendly: By default, Magpie caches feed contents for 60 minutes, cutting down on use of unnecessary bandwidth. You re free to modify the default to fit caching preferences on a per-feed basis (which is demonstrated later). If retrieval is requested after the cache has expired, Magpie will retrieve the feed only if it has been changed (by checking the Last-modified and ETag headers provided by the Web server). In addition, Magpie recognizes HTTP s GZIP content-negotiation ability when supported. Installing Magpie Like most PHP classes, installing Magpie is as simple as placing the relevant files within a directory that can later be referenced from a PHP script. The instructions for doing so follow: 1. Download Magpie from http://magpierss.sourceforge.net/. 2. Extract the package contents to a location convenient for inclusion from a PHP script. For instance, consider placing third-party classes within an aptly named directory located within the PHP_INSTALL_DIR/includes/ directory. Note that you can forego the hassle of typing out the complete path to the Magpie directory by adding its location to the include_path directive found in the php.ini file. 3. Include the Magpie class (rss_fetch.inc) within your script: require(’magpie/rssfetch.php’); That s it! You re ready to begin using Magpie. How Magpie Parses a Feed Magpie parses a feed by placing it into an object consisting of four fields: channel, image, items, and textinput. In turn, channel is an array of associative arrays, while the remaining three are associative arrays. The following script retrieves the blog.xml feed, outputting it using the print_r() statement:
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.