-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAtomRepository.cs
More file actions
52 lines (47 loc) · 1.55 KB
/
AtomRepository.cs
File metadata and controls
52 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Linq;
using System.Xml.Linq; // requires System.Xml.Linq added to References
using System.Collections.Generic;
namespace Monospace2
{
/// <summary>
/// Read Atom feed off Google/Blogspot via Google/Feedburner
/// </summary>
/// <remarks>
/// Inspired by RSSRepository at
/// http://softwareandservice.wordpress.com/2009/09/21/building-a-rss-reader-iphone-app-using-monotouch/
/// </remarks>
public static class AtomRepository
{
public static IList<AtomEntry> GetFeeds(string url)
{
var feeds = new List<AtomEntry>();
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
try
{
XNamespace ns = "http://www.w3.org/2005/Atom";
XDocument rssFeed = XDocument.Load(url);
//Console.Write(rssFeed.ToString()); // # DEBUG OUTPUT
feeds = (from item in rssFeed.Descendants(ns + "entry")
select new AtomEntry
{
Title = item.Element(ns + "title").Value,
Content = item.Element(ns + "content").Value,
Published = DateTime.Parse(item.Element(ns + "published").Value),
Url = item.Element(ns + "link").Value
}).ToList();
Console.WriteLine("feeds {0} items", feeds.Count);
}
catch(Exception ex)
{
Console.WriteLine("OOPS " + ex.Message);
//Log here
}
finally
{
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
}
return feeds;
}
}
}