黃忠成

風雪之閣- i live,so i writing
文章數 - 133, 回應數 - 125, 引用數 - 0


關於我:



黃忠成

  • 資深.NET 技術顧問
  • Run! PC 雜誌專欄作者
  • 程序員雜誌文章作者
  • PC Magazine 雜誌專欄作者
  • MSDN 專欄作者
  • MSDN 特約專屬講師
  • Microsoft .NET專屬講師
  • 台灣微軟特約技術顧問
  • 台灣微軟最有價值專家


  • 批評,指教,鼓勵, 請 寫信給我
    轉載文章請使用連結模式,
    請勿整篇Copy! 謝謝!


    我所提供的教育訓練:

    Windows Forms
    ASP.NET 2.0
    如有課程需要,請與我聯絡!

  • 我的著作:

  • 文章標籤

    全部標籤

    每月文章

    文章分類

    LINQ To XML And RSS

    前陣子上課時展示過一個例子,以LINQ To XML來讀取RSS Feed,

    當時我是使用離線的XML,最近有空把他改為直接讀取網路上的RSS.

     

     

    此例子使用VB.NET 2008寫成,如你所見,VB.NET於XML處理時,比C#來得簡潔.

     

    01 Sub 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

     


    DotBlogs Tags: .NETFramework

    posted on 2009/1/11 09:35 | 我要推薦 | 閱讀數 : 1071 | 文章分類 [ LINQ ] 訂閱

    Feedback

    目前沒有回應.

    回應

    標題
    姓名
    電子郵件 (將不會被顯示)
    個人網頁
    內容 
      登入後使用進階評論  
    Please add 6 and 5 and type the answer here:

    Powered by: