找不到类型或命名空间名称“XmlDocument".您是否缺少程序集参考? [英] The type or namespace name 'XmlDocument' could not be found. Are you missing an assembly reference?
问题描述
我正在尝试使用以下内容解析 xml 文档:
I'm trying to parse an xml document using the following:
XmlDocument doc = new XmlDocument ();
doc.LoadXml (myXMLstring);
我收到错误:
不能为类型或命名空间名称XmlDocument"成立.您是否缺少程序集参考?
The type or namespace name 'XmlDocument' could not be found. Are you missing an assembly reference?
...即使我有使用 System.Xml;
..even though I have using System.Xml;
我不确定什么是程序集引用.我正在使用 Xamarin Studio.我看到有几个文件夹可供参考.在基础项目的引用文件夹中,我没有看到 System.Xml
I'm not sure what an assembly reference is. I'm using Xamarin Studio. I see there are several folders for references. In the references folder for the base project I don't see an entry for System.Xml
但在个别平台上,我确实在其中看到了 System.Xml.
But in individual platforms I do see System.Xml in there.
我该怎么做才能清除此错误行?
What can I do to get this error line to clear?
推荐答案
正如我在 Xamarin 论坛上发布的:http://forums.xamarin.com/discussion/46042/missing-assembly-reference-for-system-xml#latest
As I posted on the Xamarin forums: http://forums.xamarin.com/discussion/46042/missing-assembly-reference-for-system-xml#latest
使用 XDocument.Parse(string)
从您的可移植类库中完成此操作.
Use XDocument.Parse(string)
to accomplish this from your Portable Class Library.
XDocument 包含在 System.Xml.Linq
命名空间中,因此您需要在类中为该命名空间添加 using 指令.
XDocument is included in the System.Xml.Linq
namespace so you will need to add the using directive for that namespace in your class.
您无法从可移植类库 (PCL) 访问 XmlDocument
的原因是因为 PCL 将仅公开在 PCL 目标的所有平台上都支持的 API.Windows Phone 8 不支持 XmlDocument,因此这在 PCL 中不可用.Windows 应用商店应用支持 XmlDocument,但它在不同的命名空间 (Windows.Data.Xml.Dom
) 中可用.因此,出于这个原因,System.Xml.XmlDocument
不能从 PCL 中使用.通过 PCL 中的 System.Xml
命名空间提供的任何其他内容都可以使用.
The reason that you cannot access XmlDocument
from a Portable Class Library (PCL) is due to the fact that a PCL will only expose APIs that are supported on all platforms that the PCL targets. Windows Phone 8 does not support XmlDocument, and so this isn't available in the PCL. Windows Store apps support XmlDocument but it is available in a different namespace (Windows.Data.Xml.Dom
). So for this reason System.Xml.XmlDocument
cannot be used from the PCL. Anything else provided through the System.Xml
namespace in the PCL is fine to use.
这篇关于找不到类型或命名空间名称“XmlDocument".您是否缺少程序集参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!