XMLReader 未知 [英] XMLReader is unknown
问题描述
按照这个介绍一可以通过导入命名空间 System.Xml
来使用 XMLReader 类.在我的 Visual Studio 项目中,我使用 .NET 4.0,但 System.Xml
未知:
Following this introduction one can use the XMLReader class by importing the namespace System.Xml
. In my Visual Studio project I use .NET 4.0, but System.Xml
is unknown:
错误 1 类型或命名空间名称Xml"在命名空间系统"(您是否缺少程序集引用?)
Error 1 The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)
在我的代码中我写道:
using System.Xml;
我缺少什么?
推荐答案
您需要对 System.Xml
程序集 (System.Xml.dll
) 的引用.我很惊讶默认情况下它不存在于项目中,但您可能已将其删除.
You need a reference to the System.Xml
assembly (System.Xml.dll
). I'm surprised it doesn't exist in the project by default, but you may have removed it.
请注意,名称空间和程序集是不同的东西 - using
指令仅导入名称空间,因此您可以使用简单名称(例如 XmlReader
)而无需进一步限定,但您仍然在项目设置中也需要 assembly 引用.
Note that namespaces and assemblies are different things - a using
directive only imports the namespace so you can use simple names (e.g. XmlReader
) without further qualification, but you still need the assembly reference as well, in the project settings.
(顺便说一句,我个人会避免直接使用 XmlReader
,除非您确实需要处理大型文档.我会尽可能使用 LINQ to XML - XDocument
>、XElement
类等.对于这些,您需要对 System.Xml.Linq
程序集的引用.)
(As an aside, I'd personally avoid using XmlReader
directly unless you really need to handle huge documents. I'd use LINQ to XML where possible - the XDocument
, XElement
classes etc. For those, you'll need a reference to the System.Xml.Linq
assembly.)
这篇关于XMLReader 未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!