這
是即前一個簡易版本的改進版。新增一個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 = "完成";
}