O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required