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?
XmlTextWriter Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files containing XML data. XmlTextWriter renders XML data to a string. This string remains in the memory of the C# program. XmlTextWriter is useful for in-memory generation of XML.
WriteAttributeString("xmlns","x",null,"abc"); By using the write methods that take a prefix as an argument you can also specify which prefix to use. In the following example, two different prefixes are mapped to the same namespace URI to produce the XML text <x:root xmlns:x="urn:1"><y:item xmlns:y="urn:1"/></x:root> .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With