且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果 xmlwriter 是推荐的,那么 xmltextwriter 的目的是什么

更新时间:2022-06-18 22:52:30

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.