C#版簡易RSS閱讀器(新增讀取OPML功能)

來源:互聯網
上載者:User


是即前一個簡易版本的改進版。新增一個treeview控制項,用來顯示讀取的OPML結果,目前我所知道地僅部落格園有OPML提供。並且它的OPML還不
是統一的格式,所以不得不在LoadOpml()方法裡添加一句判斷(藍色部分),不爽!呵呵……可能是還沒形成標準吧,也許將來就不用這麼麻煩了。我看到aowind已經把他改進版本的原始碼發到了BLOG上,看來他的動作比我快多了,呵呵……

新增原始碼(部分):
        private void LoadOpml(string url)
        {
            this.statusBar1.Text = "正在讀取" + this.textBox1.Text + "並校正…";
            this.LoadXml2Coach(this.textBox1.Text);

            this.statusBar1.Text = "正在讀取OPML相關資訊…";   
            this.LoadOpml();

            this.statusBar1.Text = "完成";
        }

        private void LoadOpml()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(this.rssFullPath);
            XmlNodeList nodeList;
            nodeList = doc.SelectNodes("/opml/body/outline");

            if(nodeList[0].HasChildNodes)
            {
   
            nodeList =
doc.SelectNodes("/opml/body/outline/outline");
            }

            this.treeView1.Nodes.Clear();

            for(int i = 0; i < nodeList.Count; i++)
            {
   
           
this.treeView1.Nodes.Add(nodeList[i].Attributes.GetNamedItem("title").InnerText);
            }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            this.LoadOpml(this.textBox1.Text);
        }

   
    private void treeView1_AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(this.rssFullPath);
            XmlNodeList nodeList;
            nodeList = doc.SelectNodes("/opml/body/outline");

            if(nodeList[0].HasChildNodes)
            {
   
            nodeList =
doc.SelectNodes("/opml/body/outline/outline");
            }

            string url = "";
            for(int i = 0; i < nodeList.Count; i++)
            {
   
           
if(this.treeView1.SelectedNode.Text.Equals(nodeList[i].Attributes.GetNamedItem("title").InnerText))
                {
   
           
    url =
nodeList[i].Attributes.GetNamedItem("xmlUrl").InnerText;
                }
            }

            this.LoadRss(url);
        }
    }

        private void LoadRss(string url)
        {
            this.statusBar1.Text = "正在讀取" + url + "並校正…";
            this.LoadXml2Coach(url);

            this.statusBar1.Text = "正在讀取BLOG相關資訊…";
            this.LoadTitle();

            this.statusBar1.Text = "正在讀取RSS內容資訊…";
            this.LoadItem();

            this.statusBar1.Text = "完成";
        }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.