![o_RssReader1.gif](/images/cnblogs_com/yul/21241/o_RssReader1.gif)
![o_RssReader2.gif](/images/cnblogs_com/yul/21241/o_RssReader2.gif)
这 是即前一个简易版本的改进版。新增一个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 = "完成";
}