Creating the XmlTextWriter

To create the XmlTextWriter, we need to give it a stream to write to. XmlTextWriter(string filename, Encoding encoding) is the simplest constructor to use. You pass in the fully qualified name of the file to write to and the encoding to write the XML text with. The code in Listing 10.20 demonstrates how to create an XmlTextWriter.

Listing 10.20.
C#
XmlTextWriter writer = new XmlTextWriter("output.xml", Encoding.UTF8);

VB
Dim writer As New XmlTextWriter("output.xml", Encoding.UTF8);

Listing 10.20 creates an XmlTextWriter that will write to the file output.xml in the root directory of a Windows CE device by using UTF-8 character encoding.

The same filename restrictions that apply to loading an XmlTextReader apply ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.