c# 用XmlWriter写xml序列化

using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Dynamic;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            //缩进元素
            settings.Indent = true;
            //每个属性单独作为一行
           // settings.NewLineOnAttributes = true;
            XmlWriter writer = XmlWriter.Create("C:\\Users\\LYY\\Desktop\\CutList.xml", settings);
            //写入文档声明
            writer.WriteStartDocument();
            //写入嵌套元素
            writer.WriteStartElement("book");
            //写入属性
            writer.WriteAttributeString("genre", "MyStery");
            writer.WriteAttributeString("id", "2001");
            writer.WriteAttributeString("ISBN", "12");
            writer.WriteAttributeString("title", "Case");

            writer.WriteStartElement("author");
            //写入单个元素,不嵌套
            writer.WriteElementString("name", "Cookie");
            writer.WriteEndElement();

            writer.WriteElementString("price", "9.99");
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();         
        }
    }
}