Question

I extract a Content node from this XML.

I use this code for extract the Content node, but i need extract all content node.

How can i do?

    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)
            {
                XNamespace ns = "urn:yahoo:answers";
                var Content = xdoc.Descendants(ns + "Content").FirstOrDefault();
                MessageBox.Show(Content.Value);
            }
        }
        else
        {
            MessageBox.Show(e.Error.Message);
        }                   
    }
Was it helpful?

Solution

 var contents = xdoc.Descendants(ns + "Content");

 foreach(var content in contents){
    MessageBox.Show(content.Value);
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top