2

I have searched and searched and searched enough until my Head aches! What I am trying to do is take an ATOM feed from here: National Weather Service Alerts and incorporate it into my program, however, I don't even KNOW where to begin :( What I want to do eventually is download the Atom feed and place it in a scrolling label. I don't want to parse it pulling out sections or anything. Just want to display the NWS alert for my area. I don't expect anyone to just write out the code or anything, but any help pointing me in the right direction for programming it simply and painlessly for an intermediate vb programmer would be greatly appreciated. Please Help!

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Greg Willard
  • 159
  • 1
  • 1
  • 8

1 Answers1

1

Here is a code sample that should work for your case. Assuming you already downloaded your Atom feed and saved it to your disk. If not, you may need a slight modification:

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

Replace "X:\vi.php.webintents" with your file location.

For System.ServiceModel.Syndication to be available, you need to add System.ServiceModel.dll to your references (.NET 4.0). For .NET 3.5 you would use System.ServiceModel.Web.dll

I used this answer as a base for SyndicationFeed usage in this example.

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
  • Yeah I seen that and downloaded but have no Idea how to use it. Never dealt with XML before. I need an example of how to use it. – Greg Willard Oct 30 '12 at 18:00
  • @GregWillard: I never dealt with RSS or Atom feeds. But I had some experience with XML. Did you look at both links? My suggestion is: make your question constructive, by adding a link to Atom feed you are interested in grabbing. And what exactly you want to do with it, illustrate with examples, and maybe some pictures. – Victor Zakharov Oct 30 '12 at 18:07
  • I have updated the link in the original post to reflect the exact atom feed I am trying to extract. What I want to design is a very small form with a label. In that label I want it to scroll the atom feed with the warning for my area when inclement weather strikes. Nothing else, just a simple alert program that I can check periodically with a Timer. Thanks for your reply. – Greg Willard Oct 30 '12 at 19:25
  • @GregWillard: check my new answer and let me know if it works for you. – Victor Zakharov Oct 30 '12 at 23:15
  • Thank you so much! Looking over the code it made a lot more sense. I have never dealt with xml before so it is an entirely different ball game to me. But thanks to your reply I feel like I have learned just a little bit about it. Now that I got a place to start I can dig deeper into it and learn much more. Your code works perfectly. I didn't download the file to the computer first, instead I pasted the url. I went ahead and put the code in the timer and added a reference. And BOOM! I got the message "No active watches or warnings at this time!" I can't thank you enough man! Thanks again! – Greg Willard Oct 31 '12 at 00:33
  • @GregWillard: Thank you for kind words - I am glad to help you with it. If you want to learn more about XML, take a look at these classes: [XmlDocument](http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx) (old way, introduced in .NET 1.1) and [XDocument](http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx) (new in .NET 3.5). I initially tried to process your `Atom` feed through them, but it did not work well, so I switched to `Syndication` namespace in the end (and found it very simple to implement). It's built specifically for that (i.e. Atom and RSS). – Victor Zakharov Oct 31 '12 at 01:36