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.
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 ...