Last active
September 5, 2015 12:34
-
-
Save iseebi/492486 to your computer and use it in GitHub Desktop.
LINQ to Hatena Fotolife
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
const string rssNs = "{http://purl.org/rss/1.0/}"; | |
const string contentNs = "{http://purl.org/rss/1.0/modules/content/}"; | |
const string dcNs = "{http://purl.org/dc/elements/1.1/}"; | |
const string hatenaNs = "{http://www.hatena.ne.jp/info/xmlns#}"; | |
var root = XElement.Load("http://f.hatena.ne.jp/hotfoto?mode=rss"); | |
var q = root.Descendants(rssNs + "item").Select(e => new HatenaFotolifeItem { | |
Title = e.Element(rssNs + "title").Value, | |
Link = e.Element(rssNs + "link").Value, | |
Description = e.Element(rssNs + "description").Value, | |
Content = e.Element(contentNs + "encoded").Value, | |
Date = e.Element(dcNsa + "date").Value, | |
ImageUrl = e.Element(hatenaNs + "imageurl").Value, | |
ImageUrlSmall = e.Element(hatenaNs + "imageurlsmall").Value, | |
ImageUrlMedium = e.Element(hatenaNs + "imageurlmedium").Value, | |
Syntax = e.Element(hatenaNs + "syntax").Value, | |
Colors = e.Element(hatenaNs + "colors").Descendants(hatenaNs + "color").Select(c => c.Value) | |
}); | |
q.Dump(); | |
} | |
// Define other methods and classes here | |
class HatenaFotolifeItem { | |
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 IEnumerable<string> Colors { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment