0

您好,我正在为 windows phone 开发应用程序,我想从网上读取 xml,所以我正在使用页面加载事件:

Dim cl As New WebClient AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted cl.DownloadStringAsync(New Uri("demo.com/1.xml",UriKind.RelativeOrAbsolute))

在 cl.DownloadStringCompleted 事件上:

Dim doc = XDocument.Load("demo.com/1.xml")

但由于某种原因我崩溃了!错误一定是我不必使用 URI:“demo.com/1.xml”,但还有一些:S

4

1 回答 1

1

DownloadStringCompleted事件有DownloadStringCompletedEventArgs。您应该使用这些参数的 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
于 2012-05-10T20:44:57.017 回答