技術をかじる猫

適当に気になった技術や言語、思ったこと考えた事など。

RSS をサクっと拾う。

環境は、C# 3.0 & .NET Framework 3.5 で動作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            XElement blog = XElement.Load("http://d.hatena.ne.jp/white-azalea/rss");
            XNamespace xmlns = "http://purl.org/rss/1.0/";
            var titles = from p in blog.Elements()
                         where p.Name.LocalName == "item"
                         select p.Element(xmlns + "title").Value;
            foreach (string title in titles)
                Console.WriteLine(title);
        }
    }
}

Namespace 忘れて悶絶してた |||orz