The No.1 i-Technology Magazine in the World !
   
 

      ES no BS
       My son's animations and music            training         Twitter            No BS IT podcast

Archives

««Mar 2010»»
SMTWTFS
  123456
78
9
10
11
12
13
14
1516
17
181920
21222324252627
28293031

RSS Feed








Subscribe to these blogs

How to write an RSS reader in AJAX

posted Friday, 18 August 2006
IBM Developers work has a tutorial on how to build an RSS reader using AJAX.  The amount of code you need to write is scary (and this is not the complete code). Adobe Flex 2 plus a simple Java programming to support DB interaction allows you to achive the same functionality using A LOT LESS coding.Just  take a look at this screen:









 
The Flex 2 code  below populates the bottom portion of the screen with financial news based on the selected stock on top ( (it does not work with a DB to store the RSS source so it'd add some 50 lines of  Java code ). The data come from the Yahoo! Finance RSS feed. The URL looks as follows: http://finance.yahoo.com/rss/headline?s=MSFT
The suffix can be MSFT or whatever is selected on top is being passed to the code below.  
Flex <mx:HTTPService> object is used through  a proxy deployed under Tomcat or any other servlet container.
The entire application code and its description can be found in this article.

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
    title="News" width="100%" height="100%"     >
    <mx:DataGrid id="newsGrid" width="100%" height="100%"
        dataProvider="{newsFeed.lastResult.channel.item}"  variableRowHeight="true">
      <mx:columns>
            <mx:DataGridColumn headerText="Date"  dataField="pubDate" width="200"/>
            <mx:DataGridColumn headerText="Title"  dataField="title"   wordWrap="true" />
            <mx:DataGridColumn headerText="Description"  dataField="description"  wordWrap="true"   />
            <mx:DataGridColumn headerText="Link"   width="130">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:LinkButton label="{data.link}"   click="navigateToURL(new URLRequest(data.link), '_blank')"/>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
      </mx:columns>
    </mx:DataGrid>
         
    <mx:HTTPService id="newsFeed" useProxy="true"  
         destination="YahooFinancialNews"     concurrency="last"
        resultFormat="e4x" fault="onFault(event)"  >
    </mx:HTTPService>
   
    <mx:Script>
        <![CDATA[
            import mx.utils.ObjectProxy;
            import mx.rpc.events.*;
            public function set security(value:String):void {
                this.title = "News: " + value;
                newsFeed.send({s:value});
            }

            private function onFault(event:FaultEvent):void {
                mx.controls.Alert.show
                (
                   "Destination:" + event.currentTarget.destination + "\n" +
                   "Fault code:" + event.fault.faultCode + "\n" +
                   "Detail:" + event.fault.faultDetail, "News feed failure"
                );
            }
        ]]>
    </mx:Script>
</mx:Panel>

tags:      

links: digg this    del.icio.us    technorati