XML Tutorials

  Home arrow XML Tutorials arrow Page 3 - Creating RSS 2.0 Feeds
XML TUTORIALS

Creating RSS 2.0 Feeds
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-17

    Table of Contents:
  • Creating RSS 2.0 Feeds
  • guid, Permalink or not
  • Creating RSS 2.0 with PHP
  • Caching and saving

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Creating RSS 2.0 Feeds - Creating RSS 2.0 with PHP


    (Page 3 of 4 )

    Great RSS 2.0 support for PHP is to be found in the feedcreator.class by Kai Blankenhorn at http://www.bitfolge.de. Unlike the previous section's XML::RSS, feedcreator.class can only create RSS feeds; it can't parse them. No matter: it's very good at that indeed.

    As illustrated in Example 4-10, the function for each feed element is named after the element, so it behaves pretty much as you would expect.

    Example 4-10. A PHP script using FeedCreator that produces RSS 2.0

    <?php
    include("feedcreator.class.php");

    $rss = new UniversalFeedCreator();
    $rss->title = "Example Feed";
    $rss->description = "This is the feed description";
    $rss->link = "http://www.example.com/";

    // Image section
    $image = new FeedImage();
    $image->title = "example logo";
    $image->url = "http://www.example.com/images/logo.gif"; $image->link = "http://www.example.com"; $image->description = "Visit Example.com!"; $rss->image = $image;

    // Item Loop
    $item = new FeedItem();
    $item->title = "Entry one";
    $item->link = http://www.example.com/entryone;
    $item->description = "This is the content of the first entry";
    $item->author = "Ben Hammersley";
    $rss->addItem($item);
    // End Item Loop

    ?>

    This is a very simple script. As you can see from the resulting feed, Example 4-11, it produces only one item. We'll be using it for more complicated things later on in the book, so in the meantime, once we've passed over the example output, we'll take a quick look at some of the special features.

    Example 4-11. An RSS 2.0 feed created with PHP

    <?xml version="1.0" encoding="ISO-8859-1"?> <!-- generator="FeedCreator 1.7.1" -->
    <rss version="2.0">
       
    <channel>
            <title>Example Feed</title>
            <description>This is the feed description</description>
            <link>http://www.example.com/</link>
            <lastBuildDate>Thu, 16 Sep 2004 20:16:22 +0100</lastBuildDate>
            <generator>FeedCreator 1.7.1</generator>
            <image> 

                <url>http://www.example.com/ images/logo.gif</url>
                <title>example logo</title> 
                <link>http://www.example.com </link>
                <description>Visit Example.com!</description>
            </image>
           
    <item>
                <title>Entry one</title> 
                <link>http://www.example.com/ entryone</link>
                <description>This is the content of the first entry</description>
                <author>Ben Hammersley</author>
           
    </item>
        </channel>
    </rss>

    More XML Tutorials Articles
    More By O'Reilly Media

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap