What is the difference between XmlTextWriter and XmlWriter?

Muhammad Basit picture Muhammad Basit · Aug 1, 2011 · Viewed 17.3k times · Source

I am looking at these these two classes in C#: XmlTextWriter and XmlWriter. Can anyone explain the difference and tell me where to use which?

Answer

SLaks picture SLaks · Aug 1, 2011

XmlWriter is an abstract class.
XmlTextWriter is a specific implementation of XmlWriter.

You should always call XmlWriter.Create.

MSDN says:

In the .NET Framework version 2.0 release, the recommended practice is to create XmlWriter instances using the XmlWriter.Create method and the XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.