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

 
Developer Updates  
Free Website Content 
 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? 
Google.com  
MYSQL

Creating an RSS Reader: the Reader
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek