仮面's profile宇宙仮面の C# 研究室.Live SpacePhotosBlogListsMore Tools Help

Blog


    February 03

    RDF を LINQ で読む

    string gooRankingUrl = "http://ranking.goo.ne.jp/rss/keyword/keyrank_all1/index.rdf";
    XDocument feedXML = XDocument.Load(gooRankingUrl);

    XNamespace d = "http://purl.org/rss/1.0/";
    XNamespace dc = "http://purl.org/dc/elements/1.1/";

    var res = from item in feedXML.Descendants(d + "item")
              select new
              {
                  Title = item.Element(d + "title").Value,
                  Link = item.Element(d + "link").Value,
                  PubDate = (item.Element(dc + "date").Value ?? ""),
                  Publisher = (item.Element(dc + "publisher").Value ?? ""),
                  Rank = (item.Element(dc + "rank").Value ?? ""),
                  Point = (item.Element(dc + "point").Value ?? ""),
                  Arrow = (item.Element(dc + "arrow").Value ?? ""),
                  Description = (item.Element(d + "description").Value ?? ""),
                  Guid = item.Element(d + "link").Value
              };

    GridView1.DataSource = res;
    GridView1.DataBind();

    結果は、こんな感じ。image