[英]How to read an Atom Feed in VB.Net
我已經搜索了足夠的搜索,直到我的頭疼! 我想做的是從這里獲取ATOM提要: National Weather Service Alerts ,並將其合並到我的程序中,但是,我什至不知道從何開始:(最終,我想做的就是下載Atom提要並下載將其放置在滾動標簽中。我不想解析它以提取節或任何內容;僅想顯示我所在區域的NWS警報。我不希望任何人僅寫出代碼或任何內容,但是會有所幫助為中級vb程序員簡單,輕松地為我指出正確的編程方向將不勝感激,請幫助!
這是一個適合您的情況的代碼示例。 假設您已經下載了Atom feed,並將其保存到磁盤中。 如果沒有,您可能需要稍作修改:
Imports System.Xml
Imports System.ServiceModel.Syndication
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim messageList As New Generic.List(Of String)
Using feedReader = XmlReader.Create("X:\vi.php.webintents")
Dim feedContent = SyndicationFeed.Load(feedReader)
If feedContent Is Nothing Then Return
For Each item As Object In feedContent.Items
messageList.Add(Convert.ToString(item.Title.Text))
Next
End Using
lbl_warnings.Text = String.Join(vbNewLine & vbNewLine, messageList)
End Sub
End Class
用您的文件位置替換"X:\\vi.php.webintents"
。
為了使System.ServiceModel.Syndication
可用,您需要將System.ServiceModel.dll
添加到引用(.NET 4.0)中。 對於.NET 3.5,您將使用System.ServiceModel.Web.dll
在此示例中,我將此答案用作SyndicationFeed
使用的基礎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.