Read XML File using LINQ with vb.net

Good Morning! All is well in Wisconsin as the Bears were destroyed by the Green Bay Packers yesterday AND the Minnesota Vikings lost as well. It just does not get better than that.

The topic today is reading an XML file using LINQ for a Silverlight application I am working on. Make it a great day!

Private Sub startXml()
    Dim client As New WebClient()
    AddHandler client.OpenReadCompleted, AddressOf finishXml
    client.OpenReadAsync(New Uri("Resources/wlsl-manifest.xml", UriKind.Relative))
End Sub
Private Sub finishXml(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
    ‘ Create a new StreamReader instance using the specified Stream object.
    Using streamreader As New StreamReader(e.Result)
        Dim manifest As XDocument = XDocument.Load(streamreader)
        Dim slides As IEnumerable(Of XElement) = manifest.Element("Slides").Elements("Slide")
        For Each slide As XElement In slides
            Dim assembly As String = slide.Element("Assembly").Value
        Next
    End Using
End Sub


Join me on Facebook

 

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: