FrontPage  Index  Search  Changes  Login

すまべん特別編「Windows Phone 7 開発ブーストアップ」スニペット

実習中に使うプログラムのスニペットです。

クラス

public class HatenaFotolifeRssItem
{
    public string Title { get; set; }
    public string Link { get; set; }
    public string Description { get; set; }
    public string Content { get; set; }
    public string Date { get; set; }
    public string ImageUrl { get; set; }
    public string ImageUrlSmall { get; set; }
    public string ImageUrlMedium { get; set; }
    public string Syntax { get; set; }
    public string[] Colors { get; set; }
}

リスト取得定数

const string rssSpace = "{http://purl.org/rss/1.0/}";
const string contentSpace = "{http://purl.org/rss/1.0/modules/content/}";
const string dcSpace = "{http://purl.org/dc/elements/1.1/}";
const string hatenaSpace = "{http://www.hatena.ne.jp/info/xmlns#}";

取得処理

var url = "http://f.hatena.ne.jp/hotfoto?mode=rss";
var targetList = [リストのインスタンス];

WebClient c = new WebClient();
c.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
{
    XDocument doc = XDocument.Load(new StringReader(e.Result));
    var q = from elem in doc.Root.Elements()
            where elem.Name.ToString().EndsWith("item")
            select new HatenaFotolifeRssItem()
            {
                Title = elem.Element(rssSpace + "title").Value,
                Link = elem.Element(rssSpace + "link").Value,
                Description = elem.Element(rssSpace + "description").Value,
                Content = elem.Element(contentSpace + "encoded").Value,
                Date = elem.Element(dcSpace + "date").Value,
                ImageUrl = elem.Element(hatenaSpace + "imageurl").Value,
                ImageUrlSmall = elem.Element(hatenaSpace + "imageurlsmall").Value,
                ImageUrlMedium = elem.Element(hatenaSpace + "imageurlmedium").Value,
                Syntax = elem.Element(hatenaSpace + "syntax").Value,
                Colors = (from color in elem.Element(hatenaSpace + "colors").Elements() where color.Name == hatenaSpace + "color" select color.Value).ToArray<string>()
            };

    targetList.ItemsSource = q;
    System.Diagnostics.Debug.WriteLine("Done.");
};
c.DownloadStringAsync(new Uri(url));
Last modified:2011/02/19 01:32:54
Keyword(s):
References: