Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Loop XML data
1 replies. Latest Post by ken tucker on November 16, 2008.
(0)
Kermit75
Member
22 points
47 Posts
11-16-2008 5:27 PM |
Hi, I am trying to loop entries in a XML document. I can not seem to get it to work.
What I would like to do is loop all video elements using the code below, writing a property to the textbox.
I can not seem to get my selection to work properly, see line 45 below.To me it resembles to SQL, wich I have used a few times before. I do not seem to get the syntax right, no matter how I try.
1 Namespace HttpServices 2 Partial Public Class Page 3 Inherits UserControl 4 5 #Region "const urls" 6 Private Const MSN_VIDEO As String = "http://catalog.video.msn.com/randomvideo.aspx?mk=us&vs=0&ff=99&c=10" 7 8 Private ReadOnly Property _NS() As XNamespace 9 Get 10 Return "urn:schemas-microsoft-com:msnvideo:catalog" 11 End Get 12 End Property 13 14 Private NS1 As XNamespace = "http://schemas.datacontract.org/2004/07/" 15 #End Region 16 17 Public Sub New() 18 InitializeComponent() 19 End Sub 20 21 Private Sub myButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) 22 Dim proxy As New WebClient() 23 AddHandler proxy.DownloadStringCompleted, AddressOf proxy_DownloadStringCompleted 24 AddHandler proxy.DownloadProgressChanged, AddressOf proxy_DownloadProgressChanged 25 proxy.DownloadStringAsync(New Uri(MSN_VIDEO)) 26 End Sub 27 28 Private Sub proxy_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) 29 If e.ProgressPercentage < 100 Then 30 ProgressText.Text = "Loading: " & e.ProgressPercentage & "%" 31 Else 32 ProgressText.Text = String.Empty 33 End If 34 End Sub 35 36 Private Sub proxy_DownloadStringCompleted(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs) 37 Dim res As String = e.Result 38 Dim doc As XDocument = XDocument.Parse(res) 39 40 Dim vids = From results In doc.Descendants(_NS +"video") Select results 41 NameList.ItemsSource = vids 42 43 ' 44 Dim xmlDoc As XDocument = XDocument.Parse(res) 45 Dim eles = From c In xmlDoc.Descendants("videos") Where c.Attribute("lcid").Value <>"" Select c 46 ProgressText.Text = eles.Count.ToString 47 End Sub 48 End Class 49 End Namespace
ken tucker
All-Star
16298 points
2,485 Posts
11-16-2008 6:28 PM |
Dim xmlDoc As XDocument = XDocument.Parse(res) Dim eles = From c In xmlDoc...<video>
ProgressText.Text = eles.Count.ToString