SilverLight项目中XDocument类的使用方法(C#)为此,我在WindowsXPServicePack3上使用VisualStudio2008。我还安装了.NETFramework3.5SP1。我的问题是我在互联网上看到的XML解析器都没有。在我的代码的顶部,我有两行我认为是必要的(使用“System.xml;”和使用“System.linq;”)但是XDocument、XMLReader、XMLDocument和我发现的任何其他行都没有工作,返回错误无法找到类型或命名空间。我有.NET框架。关于这个问题,我在互联网上绝对没有任何变化。有人有什么想法吗?编辑:当我在Silverlight项目上下文之外打开文件时,我刚刚发现它可以与XDocument一起使用。只有当我打开整个项目时才会出现问题这是一些显示问题的示例代码:usingSystem;使用System.Collections.Generic;使用System.Linq;使用System.Net;使用System.Windows;使用System.Windows。控制;使用System.Windows.Documents;使用System.Windows.Input;使用System.Windows.Media;使用System.Windows.Media.Animation;使用System.Windows.Shapes;使用System.Xml.Linq;(见下文)namespaceLastfmAzon{publicpartialclassPage:UserControl{publicPage(){}publicvoidDownloadStringCompleted(objectsender,DownloadStringCompletedEventArgse){XDocumentdoc=XDocument.Parse(e.Result);//错误2:见下文app.UserName=uname.Text;StringgetTopArtists="http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user="+app.UserName+"&api_key=d2d620af554a60f228faed8d502c4936";尤娜me.Text="再试一次!";WebClientweb=newWebClient();WebClient客户端=newWebClient();client.DownloadStringCompleted+=newDownloadStringCompletedEventHandler(DownloadStringCompleted);client.DownloadStringAsync(新Uri(getTopArtists));}}}错误1:此行包含以下错误:命名空间“System.Xml”中不存在类型或命名空间名称“Linq”(是否缺少程序集引用?)错误2:此行包含以下错误:命名空间“System.Xml”中不存在类型或命名空间名称“XDocument”(您是否缺少程序集引用?)编辑2:一旦我用谷歌搜索“添加对库的引用”意味着什么,安东尼的回答就解决了问题默认情况下,Silverlight项目将包含System.Xmldll,但XDcoument包含在System.Xml.Linqdll中,您必须将其添加到项目中。确保添加对相应XML库的引用以上就是C#学习教程的全部内容:如何在SilverLight项目中使用XDocument类(C#)。注意——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
