作为我正在处理的项目的一部分,我正在尝试将此 XML 页面 ( http://weather.yahooapis.com/forecastrss?w=2459115 ) 加载到我的 Windows Phone 8 应用程序中,并将一些值保存为变量.
我正在使用 Visual Studio 2012 专业版和 VB.net。
到目前为止,我已经搜索并尝试了多种方法,只是试图保存一个变量以开始,但我无法读取它。
这就是我到目前为止所拥有的
Partial Public Class MainPage
Inherits PhoneApplicationPage
Private XMLHANDLE As WebClient
Dim lang As String
Public Sub New()
InitializeComponent()
SupportedOrientations = SupportedPageOrientation.Portrait Or SupportedPageOrientation.Landscape
Dim XML As String = "http://weather.yahooapis.com/forecastrss?w=2459115"
XMLHANDLE = New WebClient()
XMLHANDLE.DownloadStringAsync(New Uri(XML))
AddHandler XMLHANDLE.DownloadStringCompleted, AddressOf XMLHANDLE_DownloadStringCompleted
AddHandler XMLHANDLE.DownloadProgressChanged, AddressOf XMLHANDLE_DownloadProgressChanged
End Sub
Private Sub XMLHANDLE_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
End Sub
Private Sub XMLHANDLE_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs)
If e.[Error] Is Nothing AndAlso Not e.Cancelled Then
Dim resultElements As XElement = XElement.Parse(e.Result)
lang = resultElements.Element("language").Value
Console.WriteLine(lang)
End If
End Sub
我的代码一直在此行上查找空值异常
lang = resultElements.Element("language").Value