C# 如何让Textblock显示在线XML文件中存储的信息
我已经通过Webclient下载了XML文件,但我不知道如何让我的textblock显示我想要的内容 到目前为止,我的代码是:C# 如何让Textblock显示在线XML文件中存储的信息,c#,xml,windows-phone-7,C#,Xml,Windows Phone 7,我已经通过Webclient下载了XML文件,但我不知道如何让我的textblock显示我想要的内容 到目前为止,我的代码是: private void Button_Click(object sender, RoutedEventArgs e) { WebClient wc = new WebClient(); wc.DownloadStringCompleted += HttpsCompleted; wc.Do
private void Button_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpsCompleted;
wc.DownloadStringAsync(new Uri("http://www.bing.com/HPImageArchive.aspx?
format=xml&idx=0&n=1&mkt=de-DE"));
}
private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result);
Textblock.Text =
}
}
我需要对Textblock做什么才能让它显示上面xml文件中的“版权”部分
由于我对C#和WP7完全陌生,请给我非常简单的答案-非常感谢您的时间和帮助
编辑:
我写道:
这里给出的信息起到了作用:
我认为最好使用:
XDocument xdoc = XDocument.Parse(e.Result);
String copyright = xdoc.Document.Root.Element("image").Element("copyright").Value;
image1Textblock.Text = copyright;
对不起,这在我的情况下不起作用。我得到:无法从“string”中的“System.Collection.Generic.IEnumerable”类型进行隐式转换。抱歉,请使用xdoc.Element(“xxx”).Element(“yyy”).Value。您的答案似乎是存根。请提供而不仅仅是发布一个链接。我在最上面的帖子中写下了答案
Textblock.Text = = from txt in xdoc.Descendants("copyright")
select txt.Value; //Use txt.Element("xxx").Value or txt.Attrubute("xxx").Value to extract your value
XDocument xdoc = XDocument.Parse(e.Result);
String copyright = xdoc.Document.Root.Element("image").Element("copyright").Value;
image1Textblock.Text = copyright;