Writing the XmlDocument

Once you have built and modified your XmlDocument, you can save it to a stream through the Save method on the XmlDocument class. The Save method allows you to specify the destination by using the name of a file, a Stream object, a TextWriter object, or an XmlWriter object. It is important to note that all operations that execute on an XmlDocument are made on the in-memory node tree, and changes will not be persisted until the Save method is called. Listing 11.30 shows how an XmlDocument can be saved using each overload of the Save method.

Listing 11.30.
 C# doc.Save("books.xml"); doc.Save(new FileStream("books.xml", FileMode.Open)); doc.Save(new StreamWriter("books.xml")); doc.Save(new XmlTextWriter("books.xml")); VB ...

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.