📅  最后修改于: 2022-03-11 14:49:00.882000             🧑  作者: Mango
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextWriter writer = new XmlTextWriter("Shopping_list.xml", null);
//Write the root element
writer.WriteStartElement("The_list");
//Write sub-elements
writer.WriteElementString("Fruit", "Banana");
writer.WriteElementString("Vegetable", "Carrot");
writer.WriteElementString("Drink", "Water");
// end the root element
writer.WriteEndElement();
//Write the XML to file and close the writer
writer.Close();
}
}