【问题标题】:XDocument doesn't appear to exist in System.Xml namespaceSystem.Xml 命名空间中似乎不存在 XDocument
【发布时间】:2011-01-25 05:32:33
【问题描述】:

我遇到了我认为可能是一个非常简单的问题,在开发我的第一个 WP7 应用程序时,我已经到了访问我的站点的 api 和解析 XML 的阶段,但是我只是在尝试使用 XDocument。

我四处搜索,发现这个示例代码:Load an XML file from a website into XDocument (Silverlight and Windows Phone 7) 但 XDocument 类型不存在,我知道它应该存在于我正在使用的 System.Xml 命名空间中,但错误仍然存​​在,我有什么错过了吗?

在 Visual Studio 2010 Express for Windows Phone 上开发,该类的代码如下:

using System;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Application
{
    public class DataRetriever
    {
        public void parseNewsXML()
        {
            WebClient client = new WebClient();
            client.OpenReadCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                        return;

                    Stream str = e.Result;
                    XDocument xdoc = XDocument.Load(str);
                };
        }
   } 

抛出的确切错误是: 错误 1 ​​找不到类型或命名空间名称“XDocument”(您是否缺少 using 指令或程序集引用?)

提前致谢

【问题讨论】:

    标签: c# xml windows-phone-7


    【解决方案1】:

    对于 Silverlight,该类在 System.Xml.Linq.dll 中,根据 MSDN - 所以添加对 System.Xml.Linq.dll 的引用。您还需要在代码文件顶部添加 using 指令:

    using System.Xml.Linq;
    

    (这与编译器本身提出的两个建议完全相同:“您是否缺少 using 指令或程序集引用?”)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 2011-03-01
      • 1970-01-01
      • 2011-10-19
      相关资源
      最近更新 更多