码迷,mamicode.com
首页 > Windows程序 > 详细

c# 用XmlWriter写xml序列化

时间:2019-07-31 13:03:23      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:rgs   lin   task   ESS   tin   serial   div   expr   str   

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();         
        }
    }
}

  

c# 用XmlWriter写xml序列化

标签:rgs   lin   task   ESS   tin   serial   div   expr   str   

原文地址:https://www.cnblogs.com/zhouyuqiu/p/11275388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!