Saturday, July 14, 2007

OK, I admit it after posting about cross browser mobile AJAX I ran into a BIG problem,

It seems that my mobile web portal was running out of steam processing large RSS feeds in Javascript to display on Pocket Internet Explorer.

In addition, Apple Safari seemed to suffer the same issue. (?!?#*! )

So I'm pleased to announce I've solved the problem and here are the results (or see for yourself at www.binaryrefinery.com/mobile )

image

Windows Mobile 5

 

image

I.E 7

 

image

Apple Safari (closet I've got to an iPhone)

 

So how did I get this working?   We'll I wrote a small scheduled task that runs periodically and saves on my web-server a cut down (last n articles) version of my RSS feed.   The mobile portal uses this cut down feed to display rather than the full RSS>  Here's the source of the command line driven schedule task.  I've called it RSS Cutter -

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;

namespace RSSCutter
{
  static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("RSSCutter <url of feed> <no of articles> <output path>");
                return;
            }
            int no_of_articles = 1;
            try
            {
                no_of_articles = Convert.ToInt32(args[1]);
            }
            catch
            {
            }
            RSSCutter r = new RSSCutter(args[0], no_of_articles, args[2]);
        }
    public class RSSCutter
    {
        public RSSCutter(string url, int no_of_articles, string outputpath)
        {
            WebRequest req = WebRequest.Create(url);
            WebResponse result = req.GetResponse();
            Stream receivestream = result.GetResponseStream();
           
            XmlDocument x = new XmlDocument();
            try
            {
                x.Load(receivestream);
                result.Close();
                receivestream.Close();
            }
            catch
            {

            }
            XmlNodeList nodes = x.GetElementsByTagName("item");
            if (nodes.Count == 0) return;

            int intcount = 0;
            foreach (XmlNode n in nodes)
            {
               if (intcount>no_of_articles) n.RemoveAll();
                intcount++;
               
            }

            x.Save(outputpath);
    
        }
    }
}
Technorati tags: ,
Saturday, July 14, 2007 9:53:15 PM UTC  #    Comments [0]  | 
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: