asp rss feed.

Discussion in 'XML & RSS' started by fadetoblack22, Jul 13, 2007.

  1. #1
    I have a feed: http://examplefeed.asp and I want it as an rss feed on my website.
    I want to be able to control the number of news stories that show.

    I found a script that does it below, but it doesn't work. I think it might be because it is php not asp. I don't know much about this. Also it doesn't let me control the number of stories shown. Can anyone help please....

    
    
    <?php
    /*
    
    Class RSSParser: 	2 October 2002
    
    Author:				Duncan Gough
    
    Overview:			An RSS parser that uses PHP and freely available RSS feeds to add fresh news content to your site.
    
    Installation:		Decompress the file into your webroot and include it from whichever pages on which you want
    					to display the data, e.g;
    
    					include("rss.php");
    
    Usage:				As above, just include the rss.php file from within your PHP page, and the news will appear.
    					You should find the HTML code in the functions endElement(), show_title() and show_list_box() below,
    					feel free to modify these to match your site.
    */
    
    class RSSParser	{
    
        var $title			= "";
        var $link 			= "";
        var $description 	= false;
        var $inside_item 	= false;
        
    	
    
    	function startElement( $parser, $name, $attrs='' ){
    		global $current_tag;
    
    		$current_tag = $name;
    
    		if( $current_tag == "ITEM" )
    			$this->inside_item = true;
    
    	} // endfunc startElement
    
    	function endElement( $parser, $tagName, $attrs='' ){
    		global $current_tag;
    
        	if ( $tagName == "ITEM" ) {
    
    			printf( "\t<br><b><a href='%s' target='_blank'>%s</a></b>\n", trim( $this->link ), htmlspecialchars( trim( $this->title ) ) );
        		printf( "\t<br>%s<br>\n", htmlspecialchars( trim( $this->description ) ) );
    
        		$this->title = "";
        		$this->description = "";
        		$this->link = "";
        		$this->inside_item = false;
    
        	}
    
    	} // endfunc endElement
    
    	function characterData( $parser, $data ){
    		global $current_tag;
    
    		if( $this->inside_item ){
    			switch($current_tag){
    
    				case "TITLE":
    					$this->title .= $data;
    					break;
    				case "DESCRIPTION":
    					$this->description .= $data;
    					break;
    				case "LINK":
    					$this->link .= $data;
    					break;
    
    				default:
    					break;
    
    			} // endswitch
    
    		} // end if
    
    	} // endfunc characterData
    
    	function parse_results( $xml_parser, $rss_parser, $file )	{
    
    		xml_set_object( $xml_parser, &$rss_parser );
    		xml_set_element_handler( $xml_parser, "startElement", "endElement" );
    		xml_set_character_data_handler( $xml_parser, "characterData" );
    
    		$fp = fopen("$file","r") or die( "Error reading XML file, $file" );
    
    		while ($data = fread($fp, 4096))	{
    		
    			// parse the data
    			xml_parse( $xml_parser, $data, feof($fp) ) or die( sprintf( "XML error: %s at line %d", xml_error_string( xml_get_error_code($xml_parser) ), xml_get_current_line_number( $xml_parser ) ) );
    			
    		} // endwhile
    
    		fclose($fp);
    
    		xml_parser_free( $xml_parser );
    
    	} // endfunc parse_results
    
    
    } // endclass RSSParser
    
    global $rss_url;
    
    // Set a default feed
    if( $rss_url == "" )
    	$rss_url = "add url here";
    
    $xml_parser = xml_parser_create();
    $rss_parser = new RSSParser();
    
    $rss_parser->parse_results( $xml_parser, &$rss_parser, $rss_url );
    
    
    ?>
    
    
    PHP:
     
    fadetoblack22, Jul 13, 2007 IP
  2. Midano

    Midano Peon

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If your page is ASP, you will have to find an ASP XML parser.
    If you're not sure what you're doing and don't want to mess with it - use my simple Feed 2 JavaScript tool. Just a couple of generated lines of code. Allows you to control the number of entries and other options as well.
     
    Midano, Jul 13, 2007 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    my page is php, but the rss file has a .asp extension. It doesn't seem to work in the rss code.
     
    fadetoblack22, Jul 14, 2007 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    The feed to javascript tool didn't seem to work for it either when I put in on my page.
     
    fadetoblack22, Jul 14, 2007 IP
  5. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #5
    I tried it on another rss feed and it works fine. But quite popular ones don't work at all.
     
    fadetoblack22, Jul 14, 2007 IP