我遇到了一个我认为可能非常简单的问题,在开发我的第一个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指令或程序集引用?)
提前感谢
发布于 2011-01-25 05:31:54
根据MSDN的说法,对于Silverlight来说,这个类是在System.Xml.Linq.dll
中实现的--所以添加一个对System.Xml.Linq.dll
的引用。在代码文件的顶部还需要一个using
指令:
using System.Xml.Linq;
(这两条建议与编译器本身提出的建议完全相同:“您是否缺少using指令或程序集引用?”)
https://stackoverflow.com/questions/4787387
复制相似问题