MySQL
  Home arrow MySQL arrow Page 2 - Creating an RSS Reader: the Reader
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Creating an RSS Reader: the Reader
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-02-06

    Table of Contents:
  • Creating an RSS Reader: the Reader
  • XML-related Functions
  • The Meat of the Code
  • Reading RSS Data from a Database (Optional)

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Creating an RSS Reader: the Reader - XML-related Functions
    (Page 2 of 4 )

    Now, PHP provides us with several XML-related functions, a few of which we will be using here:

    xml_parser_create() – Creates an instance of the xml parser object. Xml_parser_create() is a class. In order to use any class we need to instantiate it, or create a copy of it.

    To create a new copy:

      $xmlParser = xml_parser_create();

    xml_set_element_handler() – Searches and sets the start and end elements(tags). This function sets the start and end tags for the parser. It accepts three parameters:

    • The parser: references the parser that is calling the handler.
    • The tagname: contains the name of the element for which the handler is called.
    • The attributes: an array that contains the element's attributes.

    The parameters are used later in this article.

    xml_set_character_data_handler() – This handles the text part of the tag elements. This function takes two parameters, the parser and data.

    • The parser: references the parser that is calling the handler.
    • The data: contains the character data as a string.

    You can get more information about these and other XML functions at:

    http://uk2.php.net/manual/en/ref.xml.php

    The first thing we do is set the global variables that are going to be used by the  functions.

      $GLOBALS['titletag'] = false;

      $GLOBALS['linktag']  = false;

      $GLOBALS['descriptiontag'] = false;

      $GLOBALS['thetitletxt'] = null;

      $GLOBALS['thelinktxt'] = null;

      $GLOBALS['thedesctxt'] = null;

    These variables are going to be used to read in tag information from the RSS file that is going to be used with this reader.

    The function below deals with the starting element. This function searches through the document to find one of the three tags we discussed earlier:

    function startTag( $parser, $tagName, $attrs ) {

         switch( $tagName ) {

               

          case 'TITLE':

            $GLOBALS['titletag'] = true;

            break;

          case 'LINK':

            $GLOBALS['linktag'] = true;

            break;

          case 'DESCRIPTION':

            $GLOBALS['descriptiontag'] = true;

            break;

        }

      }

    This next function deals with the end tag:

      function endTag( $parser, $tagName ) {

         switch( $tagName ) {

               

          case 'TITLE':

            echo "<p><b>" . $GLOBALS[the'titletxt'] . "</b><br/>";

            $GLOBALS['titletag'] = false;

            $GLOBALS['thetitletxt'] = "";

            break;

          case 'LINK':

            echo "Link: <a href="". $GLOBALS['thelinktxt'] . "">" .
    $GLOBALS['thelinktxt'] . "</a><br/>";

            $GLOBALS['linktag'] = false;

            $GLOBALS['thelinktxt'] = "";

            break;

          case 'DESCRIPTION':

            echo "Desc: " . $GLOBALS['thedesctxt'] . "</p>";

            $GLOBALS['descriptiontag'] = false;

            $GLOBALS['thedesctxt'] = "";

            break;

        }

      }

    This next function verifies the tag that the text belongs to. Once we know which tag it is that we are dealing with, we set the global variable to true.

      function txtTag( $parser, $text ) {

           if( $GLOBALS['titletag'] == true ) {

            $GLOBALS['thetitletxt'] .= htmlspecialchars( trim
    ($text) );

               

        } else if( $GLOBALS['linktag'] == true ) {

            $GLOBALS['thelinktxt']  .= trim( $text );

        } else if( $GLOBALS['descriptiontag'] == true ) {

            $GLOBALS['thedesctxt'] .= htmlspecialchars( trim
    ( $text ) );

        }

      }

    More MySQL Articles
    More By Jacques Noah


       · Hope you enjoyed my article. Any comments are very welcome
       · thank you for this tutorial,it's very detail and easy understand,but i think...
     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway