【问题标题】:Extract all content nodes提取所有内容节点
【发布时间】:2013-09-02 12:54:15
【问题描述】:

我从this XML.中提取了一个内容节点

我使用此代码提取内容节点,但我需要提取所有内容节点。

我该怎么办?

    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);
        }                   
    }

【问题讨论】:

  • 如果您对答案感到满意,请不要忘记将其标记为已接受。这不是您第一次忽略它。
  • 我无法标记答案,因为我没有 15 名声望 :(
  • 我已经阅读了它,但它并没有解决问题!
  • 在你的声望达到 15 之前你不能投票。但是你可以而且你应该接受答案。否则人们为什么要帮助你?

标签: c# xml windows-phone-7 xmlnode


【解决方案1】:
 var contents = xdoc.Descendants(ns + "Content");

 foreach(var content in contents){
    MessageBox.Show(content.Value);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 2015-07-20
    • 2018-06-13
    相关资源
    最近更新 更多