1. #1
    Sencha User
    Join Date
    Aug 2011
    Location
    United Kingdom
    Posts
    8
    Vote Rating
    0
    craigwalshuk is on a distinguished road

      0  

    Default Help with RSS reader

    Help with RSS reader


    I have been having a problem reading the data from a remote RSS feed and loading it into my application. I have copied from the API documentation but can't see where I'm going wrong. Could someone please post some working example code that I can adapt to my needs. Here is what I have so far:

    Code:
    Ext.setup({
        tabletStartupScreen: 'tablet_startup.png',
        phoneStartupScreen: 'phone_startup.png',
        icon: 'icon.png',
        glossOnIcon: false,
        onReady: function() {
    	
    		Ext.regModel('item', {
    			fields: ['title', 'description']
    		});
    
    
    		var store = new Ext.data.Store({
    			model: 'item',
    			autoLoad : true,
    			proxy: {
    				type: 'ajax',
    				url : 'http://feeds.feedburner.com/OMNEWS',
    				reader: {
    					type: 'xml',
    					record: 'item'
    				}
    			}
    		});
    		
    		var newsList = new Ext.Component({
    			title: 'News',
    			cls: 'newslist',
    			scroll: 'Vertical',
    			tpl: [
    				'<tpl for=".">',
    					'<div class="newsItem">',
    						'<h2>{title}</h2>',
    					'</div>',
    				'</tpl>'
    			]
    		});
    		
    		var panel = new Ext.TabPanel({
    			fullscreen: true,
    			ui: 'light',
    			cardSwitchAnimation: 'slide',
    			items: [newsList]
    		});
    	
    	}
    });
    Thank you for your help!

    Kind Regards,
    Craig Walsh.

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Posts
    10
    Vote Rating
    0
    appsandcheese.com is on a distinguished road

      0  

    Red face


    Craig,

    You can't use ajax to read the feed from different domain due to crossdomain policy. There are few ways however to get this going.

    1. Implement simple proxy on your server that will fetch the xml feed then specify proxy file as the url.
    For example
    Code:
    <?php
    	//	proxy.php
    	header ("Content-Type:text/xml");
    	$file = file_get_contents('http://feeds.feedburner.com/OMNEWS');
    	$xml = simplexml_load_string($file);
    	echo $xml;
    	exit;
    ?>
    Code:
    var store = new Ext.data.Store({
                model: 'item',
                autoLoad : true,
                proxy: {
                    type: 'ajax',
                    url : 'http://feeds.feedburner.com/OMNEWS',
                    reader: {
                        type: 'xml',
                        record: 'item'
                    }
                }
    });
    2. Instead of dealing with xml you can convert xml feed into JSON format as it is easier to deal with JSON
    Code:
    <?php
        //    proxy.php
        header('Content-type: application/json');
        $file = file_get_contents('http://feeds.feedburner.com/OMNEWS');
        $xml = simplexml_load_string($file);
        
        echo json_encode($xml);
        exit;
    ?>
    3. Instead implementing your own proxies you can sign up with http://code.google.com/apis/feed/ and have it do all the xml to json conversion for you. In this case you'll have to access the feed via JSONP Store.

Thread Participants: 1

Tags for this Thread