views:

47

answers:

1

I like to make an app that reads articles from a website ad RSS or JSON. What method do I use to grab the XML or JSON to my app? How do I tell when the data is available locally?

Thanks.

Edit: I'm using Objective-c for iOS. I need code for iOS please.

A: 

I don't know what programming language you use but I can share a code snippet I developed in C#. It gets the rss content of a wordpress blog, parses that content, and displays 3 top blog post links.

int blogitemcount = 3;
string wordpressBlog = "wordpress blog address";
System.Net.WebClient wc = new System.Net.WebClient();
byte[] buffer = wc.DownloadData("http://" + wordpressBlog + "/feed/rss");
wc.Dispose();
wc = null;
if(buffer.Length > 0) {
    string content = Encoding.UTF8.GetString(buffer);
    XmlDocument xdoc = new XmlDocument();
    xdoc.LoadXml(content);
    XmlNodeList nodes=xdoc.SelectNodes("/rss/channel/item");
    string linkformat = "<a href='{0}' target='_blank' class='blogitem'>{1}</a>";
    for(int i=0; i < nodes.Count && i < blogitemcount;i++ )
    {
        XmlNode n = nodes[i];
        this.ltItems.Text += string.Format(linkformat, n.SelectSingleNode("link").InnerText, n.SelectSingleNode("title").InnerText);
    }
}
Zafer
Thanks. I'm using objective-c for ios.
Moshe