/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example20_1.cs illustrates the XmlTextWriter class
*/
using System;
using System.Xml;
public class Example20_1
{
public static void Main()
{
// use the XmlTextWriter to open a new XML file
XmlTextWriter xw = new XmlTextWriter(@"Cust4.xml",
System.Text.Encoding.UTF8);
// write the document declaration
xw.WriteStartDocument();
// write the first element
xw.WriteStartElement("NewDataSet");
// write the first customer
xw.WriteStartElement("Customers");
xw.WriteElementString("CustomerID", "ALFKI");
xw.WriteElementString("CompanyName", "Alfreds Futterkiste");
xw.WriteElementString("ContactName", "Maria Anders");
xw.WriteElementString("ContactTitle", "Sales Representative");
xw.WriteElementString("Address", "Obere Str. 57");
xw.WriteElementString("City", "Berlin");
xw.WriteElementString("PostalCode", "12209");
xw.WriteElementString("Country", "Germany");
xw.WriteElementString("Phone", "030-0074321");
xw.WriteElementString("Fax", "030-0076545");
xw.WriteEndElement();
// write the second customer
xw.WriteStartElement("Customers");
xw.WriteElementString("CustomerID", "BONAPP");
xw.WriteElementString("CompanyName", "Bon App'");
xw.WriteElementString("ContactName", "Laurence Lebihan");
xw.WriteElementString("ContactTitle", "Owner");
xw.WriteElementString("Address", "12, rue des Bouchers");
xw.WriteElementString("City", "Marseille");
xw.WriteElementString("PostalCode", "13008");
xw.WriteElementString("Country", "France");
xw.WriteElementString("Phone", "91.24.45.40");
xw.WriteElementString("Fax", "91.24.45.41");
xw.WriteEndElement();
// end the NewDataSet element
xw.WriteEndElement();
// end the document
xw.WriteEndDocument();
// flush and close
xw.Flush();
xw.Close();
}
}
/**/