c# 用XmlWriter写xml序列化
Posted zhouyuqiu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
以上是关于c# 用XmlWriter写xml序列化的主要内容,如果未能解决你的问题,请参考以下文章
在C#中 如何序列化图片 用System.Xml.Serialization.XmlSerializer这个可以吗?如果可以的话怎样使用?