📜  XMLWriter 编写 xml C# 代码示例

📅  最后修改于: 2022-03-11 14:49:00.882000             🧑  作者: Mango

代码示例1
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();
  }
}