LoginSignup
1
2

More than 3 years have passed since last update.

【C#】RSSフィードを読み込む

Posted at

備忘録。
RSSフィードを読み込む。

D01tsumaTask2.cs

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

namespace D01tsumathTask2
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = @"http://d01tsumath.hatenablog.com/rss";
            Console.WriteLine("ブログRSS取得します!");

            try
            {
                // RSS読み込み
                XElement element = XElement.Load(url);

                // channelの取得
                XElement channelElement = element.Element("channel");

                //itemの取得
                IEnumerable<XElement> elementItems = channelElement.Elements("item");

                for (int i = 0; i < 5; i++)
                {
                    XElement item = elementItems.ElementAt(i);
                    Console.WriteLine($" タイトル : <a href='{item.Element("link").Value}'>{item.Element("title").Value}</a>");
                }

                Console.WriteLine("完了");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2