Saturday, 31 August 2013

c# wp7 xml node xdocument

c# wp7 xml node xdocument

I need to extract an XML node of this XML document:
http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=dj0yJmk9TU1hbThtN0IwRjYzJmQ9WVdrOVMzWjVNR05GTXpBbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kYg--YahooDemo&query=cars
i need acces the node Question. i use this code but it dosen't work:
private void button1_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpsCompleted;
wc.DownloadStringAsync(new
Uri("http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=dj0yJmk9TU1hbThtN0IwRjYzJmQ9WVdrOVMzWjVNR05GTXpBbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kYg--YahooDemo&query=cars"),
UriKind.RelativeOrAbsolute);
}
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 Question = doc.Descendants(XName.Get("Question",
"http://http://answers.yahooapis.com/")).FirstOrDefault();
MessageBox.Show(Question.Value);
}
}
else
{
MessageBox.Show(e.Error.Message);
}
}

No comments:

Post a Comment