Vb.net “适用于windows phone的VB silverlight”;下载StringAsync";
您好,我正在为windows phone开发应用程序,我想从web读取xml 因此,我使用页面加载事件:Vb.net “适用于windows phone的VB silverlight”;下载StringAsync";,vb.net,silverlight,windows-phone-7,Vb.net,Silverlight,Windows Phone 7,您好,我正在为windows phone开发应用程序,我想从web读取xml 因此,我使用页面加载事件: Dim cl作为新的网络客户端 AddHandler cl.DownloadStringCompleted,cl_DownloadStringCompleted的地址 cl.DownloadStringAsync(新Uri(“demo.com/1.xml”,UriKind.RelativeOrAbsolute)) 在cl.DownloadStringCompleted事件上: Dim doc
Dim cl作为新的网络客户端
AddHandler cl.DownloadStringCompleted,cl_DownloadStringCompleted的地址
cl.DownloadStringAsync(新Uri(“demo.com/1.xml”,UriKind.RelativeOrAbsolute))
在cl.DownloadStringCompleted事件上:
Dim doc=XDocument.Load(“demo.com/1.xml”)
但由于某种原因,我崩溃了!
错误一定是因为我没有使用URI:“demo.com/1.xml”,而是使用了其他一些URI:S下载StringCompleted事件具有
下载StringCompletedEventArgs
。您应该使用这些参数的Result属性
Dim client As New WebClient()
AddHandler client.DownloadStringCompleted, AddressOf ClientOnDownloadStringCompleted
client.DownloadStringAsync(New Uri("http://demo.com/xml"))
和处理程序:
Private Sub ClientOnDownloadStringCompleted(sender As Object, args As DownloadStringCompletedEventArgs)
Dim doc = XDocument.Parse(args.Result)
End Sub
args.Result
是请求中的字符串内容还是文件名?如果它是一个包含xml的字符串,那么您需要调用XDocument.Parse
,而不是Load
。