LINQ To XML And RSS
2009-01-11 09:51
405 查看
前陣子上課時展示過一個例子,以LINQ To XML來讀取RSS Feed,
當時我是使用離線的XML,最近有空把他改為直接讀取網路上的RSS.
01
Sub LoadRSS() LoadRSS()
02
Dim request As System.Net.WebRequest = _
03
System.Net.WebRequest.Create("http://www.dotblogs.com.tw/code6421/category/1530.aspx/rss")
04
Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), System.Net.HttpWebResponse)
05
Dim dataStream As System.IO.Stream = response.GetResponseStream()
06
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(dataStream)
07
Using (reader)
08
Dim xmlDoc = XDocument.Load(reader)
09
Dim result = From s1 In xmlDoc...<item> Select s1
10
11
12
For Each item In result
13
Console.WriteLine(item.<title>.Value)
14
Next
15
Console.ReadLine()
16
End Using
17
End Sub
此例子使用VB.NET 2008寫成,如你所見,VB.NET於XML處理時,比C#來得簡潔.
當時我是使用離線的XML,最近有空把他改為直接讀取網路上的RSS.
01
Sub LoadRSS() LoadRSS()
02
Dim request As System.Net.WebRequest = _
03
System.Net.WebRequest.Create("http://www.dotblogs.com.tw/code6421/category/1530.aspx/rss")
04
Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), System.Net.HttpWebResponse)
05
Dim dataStream As System.IO.Stream = response.GetResponseStream()
06
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(dataStream)
07
Using (reader)
08
Dim xmlDoc = XDocument.Load(reader)
09
Dim result = From s1 In xmlDoc...<item> Select s1
10
11
12
For Each item In result
13
Console.WriteLine(item.<title>.Value)
14
Next
15
Console.ReadLine()
16
End Using
17
End Sub
此例子使用VB.NET 2008寫成,如你所見,VB.NET於XML處理時,比C#來得簡潔.
相关文章推荐
- Linq to XML---网站地图和RSS Feed
- ASP.NET的SEO(五):Linq to XML---网站地图和RSS Feed
- 使用linq to xml 快速创建自己的Rss
- LinqTOXML DescendantNodes、DescendantNodesAndSelf和Descendants、DescendantsAndSelf方法
- 使用linq to xml 快速创建自己的Rss
- 使用linq to xml 快速创建自己的Rss 之二 Syndication篇
- Linq to XML---网站地图和RSS Feed(ASP.NET的SEO)
- 使用linq to xml 快速创建自己的Rss
- Preview Word files (docx) in HTML using ASP.NET, OpenXML and LINQ to XML
- Linq to XML 用一句话读出RSS文章列表代码
- ASP.NET的SEO:Linq to XML---网站地图和RSS Feed
- Preview Word files (docx) in HTML using ASP.NET, OpenXML and LINQ to XML
- 使用linq to xml 快速创建自己的Rss -- 转载自 半途 blog
- An Extensive Examination of LINQ: Querying and Searching XML Documents Using LINQ to XML
- LinqToXml Ancestors和AncestorsAndSelf方法
- 使用linq to xml 快速创建自己的Rss
- ASP.NET的SEO:Linq to XML---网站地图和RSS Feed (6)
- Linq to XML 用一句话读出RSS文章列表代码
- [导入]使用linq to xml 快速创建自己的Rss
- Google Merchant How To Setup A Live XML Data Feed With MySql and PHP