http://www.cnblogs.com/aowind/archive/2005/03/16/119841.html
这次做成了博客园的专用阅读器了,给左边加上了一个treeview,专门用来显示博客园的分类和博客列表。嘿嘿
下面是新版的图片
上次的源代码已提供出来了
http://www.cnblogs.com/aowind/archive/2005/03/17/120543.html
这次就只发一些新增加的内容
首先,要加一个treeview,当然加在哪里自己定了,一般习惯就加在我上图这里了
先给它定义一个根和两个子节点,名字分别是:博客园,博客园分类,博客园列表
下面先来写读博客园分类的过程
'读取博客园分类
Private Sub loadport()
Dim i As Integer
Dim xmlPort As New XmlDocument
StatusBar1.Text = "正在读取博客园分类信息"
xmlPort.Load("http://www.cnblogs.com/CatalogOpml.aspx")
xmlPort.Save(Application.StartupPath & "~port.xml")
Dim Portnodelist As XmlNodeList
Portnodelist = xmlPort.SelectNodes("/opml/body/outline/outline")
For i = 0 To Portnodelist.Count - 1
TreeView1.Nodes.Item(0).Nodes.Item(0).Nodes.Add(Portnodelist(i).Attributes.ItemOf("title").InnerText())
Next
StatusBar1.Text = "完成"
End Sub
Private Sub loadport()
Dim i As Integer
Dim xmlPort As New XmlDocument
StatusBar1.Text = "正在读取博客园分类信息"
xmlPort.Load("http://www.cnblogs.com/CatalogOpml.aspx")
xmlPort.Save(Application.StartupPath & "~port.xml")
Dim Portnodelist As XmlNodeList
Portnodelist = xmlPort.SelectNodes("/opml/body/outline/outline")
For i = 0 To Portnodelist.Count - 1
TreeView1.Nodes.Item(0).Nodes.Item(0).Nodes.Add(Portnodelist(i).Attributes.ItemOf("title").InnerText())
Next
StatusBar1.Text = "完成"
End Sub
上次很多东东都没说细,这次说细一点,
http://www.cnblogs.com/CatalogOpml.aspx这个就是博客园分类列表的XML地址了,在博客园的首面有公布的
接下来存入一个临时文件中以供后面使用
TreeView1.Nodes.Item(0).Nodes.Item(1).Nodes.Add()
这个方法就是给treeview1根节点下面的第一个节点添加子节点了
listnodelist(i).Attributes.ItemOf("title").InnerText()
这个方法是取出XML中这一节点列表中INDEX为I的项的title属性的值
再下来是读取博客列表了,就不用重复说明
'读取博客列表
Private Sub loadlist()
Dim i As Integer
Dim xmlList As New XmlDocument
StatusBar1.Text = "正在读取博客列表信息"
xmlList.Load("http://www.cnblogs.com/Opml.aspx")
xmlList.Save(Application.StartupPath & "~list.xml")
Dim listnodelist As XmlNodeList
listnodelist = xmlList.SelectNodes("/opml/body/outline")
For i = 0 To listnodelist.Count - 1
TreeView1.Nodes.Item(0).Nodes.Item(1).Nodes.Add(listnodelist(i).Attributes.ItemOf("title").InnerText())
Next
StatusBar1.Text = "完成"
End Sub
Private Sub loadlist()
Dim i As Integer
Dim xmlList As New XmlDocument
StatusBar1.Text = "正在读取博客列表信息"
xmlList.Load("http://www.cnblogs.com/Opml.aspx")
xmlList.Save(Application.StartupPath & "~list.xml")
Dim listnodelist As XmlNodeList
listnodelist = xmlList.SelectNodes("/opml/body/outline")
For i = 0 To listnodelist.Count - 1
TreeView1.Nodes.Item(0).Nodes.Item(1).Nodes.Add(listnodelist(i).Attributes.ItemOf("title").InnerText())
Next
StatusBar1.Text = "完成"
End Sub
再接下来就是treeview节点的选择事件的处理过程了
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Select Case TreeView1.SelectedNode.Text
Case "博客园分类"
loadport()
Case "博客列表"
loadlist()
Case "博客园"
Case Else
Dim i, j As Integer
Dim xmltitle As New XmlDocument
xmltitle.Load(Application.StartupPath & "~port.xml")
Dim nodelist As XmlNodeList
nodelist = xmltitle.SelectNodes("/opml/body/outline/outline")
j = nodelist.Count - 1
For i = 0 To j
If nodelist(i).Attributes.ItemOf("title").InnerText() = TreeView1.SelectedNode.Text Then
TextBox1.Text = nodelist(i).Attributes.ItemOf("xmlUrl").InnerText()
thread = New Thread(AddressOf loadrss)
thread.Start()
Exit For
End If
Next
xmltitle.Load(Application.StartupPath & "~list.xml")
nodelist = xmltitle.SelectNodes("/opml/body/outline")
j = nodelist.Count - 1
For i = 0 To j
If nodelist(i).Attributes.ItemOf("title").InnerText() = TreeView1.SelectedNode.Text Then
TextBox1.Text = nodelist(i).Attributes.ItemOf("xmlUrl").InnerText()
thread = New Thread(AddressOf loadrss)
thread.Start()
Exit For
End If
Next
End Select
End Sub
Select Case TreeView1.SelectedNode.Text
Case "博客园分类"
loadport()
Case "博客列表"
loadlist()
Case "博客园"
Case Else
Dim i, j As Integer
Dim xmltitle As New XmlDocument
xmltitle.Load(Application.StartupPath & "~port.xml")
Dim nodelist As XmlNodeList
nodelist = xmltitle.SelectNodes("/opml/body/outline/outline")
j = nodelist.Count - 1
For i = 0 To j
If nodelist(i).Attributes.ItemOf("title").InnerText() = TreeView1.SelectedNode.Text Then
TextBox1.Text = nodelist(i).Attributes.ItemOf("xmlUrl").InnerText()
thread = New Thread(AddressOf loadrss)
thread.Start()
Exit For
End If
Next
xmltitle.Load(Application.StartupPath & "~list.xml")
nodelist = xmltitle.SelectNodes("/opml/body/outline")
j = nodelist.Count - 1
For i = 0 To j
If nodelist(i).Attributes.ItemOf("title").InnerText() = TreeView1.SelectedNode.Text Then
TextBox1.Text = nodelist(i).Attributes.ItemOf("xmlUrl").InnerText()
thread = New Thread(AddressOf loadrss)
thread.Start()
Exit For
End If
Next
End Select
End Sub
三个过程,还算清淅了,嘿嘿!这个功能就完成了
当然还能加上别的Opml的导入功能
我这里分类名是死的,其实这些也是可以动态取出来的。