-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRssParser.cs
50 lines (45 loc) · 1.54 KB
/
RssParser.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace RSS2Pushover
{
public class FeedParser
{
public List<Item> ReadFeed(string url)
{
try
{
XDocument doc = XDocument.Load(url);
var entries = from item in doc.Root.Descendants().First(i => i.Name.LocalName == "channel").Elements().Where(i => i.Name.LocalName == "item").Take(10)
select new Item
{
Content = item.Elements().First(i => i.Name.LocalName == "description").Value,
Url = item.Elements().First(i => i.Name.LocalName == "link").Value,
Title = item.Elements().First(i => i.Name.LocalName == "title").Value,
Guid = item.Elements().First(i => i.Name.LocalName == "guid").Value
};
return entries.ToList();
}
catch (Exception e)
{
Console.WriteLine("RSS PARSE ERROR " + e.Message);
return new List<Item>();
}
}
}
public class Item
{
public string Title { get; set; }
public string Url { get; set; }
public string Content { get; set; }
public string Guid { get; set; }
public Item()
{
Title = "";
Url = "";
Content = "";
}
}
}