768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

Sort Collection Rss By PubDate in ActionScript

XML can be friendly and some times can be nightmare for me. A few days ago, i have task to sort rss results from multiple sites by the pubDate. If you see the source xml of rss, each websites has common format pubDate : Wed, 03 Nov 2010 22:31:34 +0000 . As my experience, converting string date to datetime in actionScript using DateField.stringToDate not always give you actual result and my client want get the results are sorted up to milliseconds. There are some suggestion to use XSLT to sort xml by pubDate, but my application is desktop Air, how to do that without connect to webservice and parsing the rss result to XSLT ?

ActionScript is very fast to recursive big of data. So I decide to sort rss results in XMLListCollection, here is my codes:

//_result are composite of total rss results from a number of websites.
    // _results += new XMLList(XML(event.result)..item);
    public function sortRss(_results:XMLList, sortedResults:XMLListCollection):void{
      var sort:Sort = new Sort();
      sortedResults = new XMLListCollection(_results);
          
      var sortField:SortField = new SortField();
      sortField.compareFunction = sortRssByDate;
      sortField.descending = true;
     sort.fields = [sortField]
           
      sortedResults.sort = sort;
      sortedResults.refresh();
    }
    
    public var months:Array = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

    private function convertPubDate(_pubDate:String):Date{
      var arrDate:Array = _pubDate.split(/\s/gi);
      var _strDate:String = arrDate[0]+" "+arrDate[1]+" "+arrDate[2]+" "+arrDate[3];
      var arrTime:Array = arrDate.length > 5 ? String(arrDate[4]).split(/\:/gi) : [];        
      var _hour:Number = arrTime.length == 3 ? Number(arrTime[0]) : 0;
      var _minute:Number = arrTime.length == 3 ? Number(arrTime[1]) : 0;
      var _second:Number = arrTime.length == 3 ? Number(arrTime[2]) : 0;
      var _dateTime:Date = new Date(Number(arrDate[3]), months.indexOf(arrDate[2]),Number(arrDate[1]),_hour,_minute,_second);
      return _dateTime;
    }
      
    private function sortRssByDate(itemA:Object,itemB:Object,fields:Array = null):int{
    var dateA:Date = convertPubDate(itemA.pubDate);
      var dateB:Date = convertPubDate(itemB.pubDate);
      return ObjectUtil.dateCompare(dateA,dateB);
  }

Finally, it works without crash the application. I have tested from 10 websites with 25 items for each rss per 1 box, and i have 10 boxes. Total 100 websites rss that have to be sorted together by pubdate and grand total item is 2500 items.

2 Response to "Sort Collection Rss By PubDate in ActionScript"

Betris Maya said...

HOW I GET A LEGIT LOAN @ 2% INTEREST RATE
I am a mum of three little kids. When i could not face my Debt any more, my son was on hospital bed for surgery that involve huge money and i also needed some money to refinance and get a good home then i have to seeks for Assistance from friends and when there was no hope any more i decide to go online to seek a loan and i find MARIA HAUSTIN Loan company (mariahaustin@hotmail.com) with 2% interest Rate and applied immediately with my details as directed. Within seven Days of my application She wired my loan amount with No hidden charges and i could take care of my son medical bills, Renew my rent bill and pay off my debt. I will advice every loan seeker to contact MARIA HAUSTIN Company with mariahaustin@hotmail.com For easy and safe transaction.

*Full Name:_________

*Address:_________

*Tell:_________

*loan amount:_________

*Loan duration:_________

*Country:_________

*Purpose of loan:_________

*Monthly Income:__________

*Occupation__________

*Next of kins :_________

*Email :_________

Contact her company Via Email: mariahaustin@hotmail.com

Anonymous said...

My names are Jessica Switch from united states. Merry Christmas in advance friends, become rich today and take the risk of transforming your own life. Try and get a blank ATM card today from (MR TOM HOOPER) and be among the lucky ones who are benefiting from this cards. This PROGRAMMED blank ATM card is capable of hacking into any ATM machine, anywhere in the world. I got to know about this BLANK ATM CARD when I was searching for job online about a month ago.. It has really changed my life for good and now I can say I'm rich because am a living testimony. The least money I get in a day with this card is about $4,000. Every now and then I keeping pumping money into my account. Though is illegal, there is no risk of being caught, because it has been programmed in such a way that it is not traceable, it also has a technique that makes it impossible for the CCTV to detect you.. For details on how to get yours today, E-mail the hackers on ( Tomhooperhackersworld@yahoo.com ).

 
powered by Blogger