我正在尝试从 xml 文件中删除一个节点,一切正常,但有时会发生 xml 网页未加载的情况。这是我的代码:
private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
if (e.Error == null)
{
XDocument doc = XDocument.Parse(e.Result, LoadOptions.None);
var lyric = doc.Descendants(XName.Get("Lyric", "http://api.chartlyrics.com/")).FirstOrDefault();
TextBlock1.Text = lyric.Value;
}
}
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpsCompleted;
wc.DownloadStringAsync(new Uri("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=michael%20jackson&song=bad));
}
我已经阅读过使用 WebException 来处理这个“错误”,但我无法使用它。有人可以帮我吗?