如果 xmlwriter 是推荐的,那么 xmltextwriter 的目的是什么 [英] What is the purpose of xmltextwriter if xmlwriter is the recommended one

查看:34
本文介绍了如果 xmlwriter 是推荐的,那么 xmltextwriter 的目的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN:

尽管 Microsoft .NET Framework 包含 XmlTextWriter 类,它是 XmlWriter 类的具体实现,但在 .NET Framework 2.0 版中,推荐的做法是使用 Create 方法创建 XmlWriter 实例.

Although the Microsoft .NET Framework includes the XmlTextWriter class, which is a concrete implementation of the XmlWriter class, in version 2.0 of the .NET Framework, the recommended practice is to create XmlWriter instances using the Create method.

那么,如果我们无论如何必须使用 XmlWriter,那么拥有 XmlTextWriter 的目的是什么?为什么会存在?

So if we have to use XmlWriter anyhow what is the purpose of having XmlTextWriter? why do it exist?

推荐答案

XMLWriter 是一个抽象类,它充当所有 XML 编写器的基本类型.它是在 .NET 1.1 中引入的.XMLTextWriterXMLWriter 的许多可能实现之一,专门用于创建文本表示.它也在 .NET 1.1 中引入.

XMLWriter is an abstract class which acts as the base type for all XML writers. It was introduced with .NET 1.1. XMLTextWriter is one of many possible implementations of XMLWriter, specifically to create a text representation. It was also introduced with .NET 1.1.

现在,在 .NET 2 中,XMLWriter 类被扩展为包含额外的静态 Create 方法,例如XMLWriter.Create(string)将 XML 写入文件.这些方法创建一个实现 XMLWriter 的内部类型的对象(因此它使用的实际类型是不可见的).这样,您就不必担心实际的实现,而只需使用公共基类型 XMLWriter 即可使用它.

Now, in .NET 2, the XMLWriter class was extended to contain additional static Create methods, e.g. XMLWriter.Create(string) to write the XML to a file. These methods create an object of an internal type that implements XMLWriter (so the actual type it uses is not visible). That way, you don’t have to worry about the actual implementation but can just use the common base type, XMLWriter, to use it.

那些Create 方法可以完全替代之前的XMLTextWriter,但是由于.NET 框架想要保持向后兼容,它必须保留XMLTextWritercode> 尽管 XMLWriter 现在能够处理这些情况.

Those Create methods could replace the previous XMLTextWriter completely, but since the .NET framework wants to remain backwards compatible, it had to keep the XMLTextWriter although the XMLWriter is now capable of handling those cases.

这篇关于如果 xmlwriter 是推荐的,那么 xmltextwriter 的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆