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#操作Xml:使用XmlWriter写Xml
假定创建了XmlWriter的实例变量xmlWriter,下文中将使用此实例变量写Xml 1.如何使用XmlWriter写Xml文档声明 ? // WriteStartDocument方法可以接受一个 ...
- 使用XmlWriter写Xml
假定创建了XmlWriter的实例变量xmlWriter,下文中将使用此实例变量写Xml 1.如何使用XmlWriter写Xml文档声明 ? // WriteStartDocument方法可以接受一个 ...
- Windows phone 之XML序列化与反序列化
为什么要做序列化和反序列化? 一个回答: 我们都知道对象是不能在网络中直接传输的,不过还有补救的办法.XML(Extensible Markup Language)可扩展标记语言,本身就被设计用来存储 ...
- C#操作Xml:XmlSerializer 对象的Xml序列化和反序列化
这篇随笔对应的.Net命名空间是System.Xml.Serialization:文中的示例代码需要引用这个命名空间. 为什么要做序列化和反序列化? .Net程序执行时,对象都驻留在内存中:内存中的对 ...
- XML文件的写,集合XML序列化(写)。XML文件的读,递归遍历
XML文件:必须要有一个节点.检验xml文件,可以用浏览器打开,能打开表示对,否则错. 处理方法: DOM:XmlDocument文档对象模型 Sax(事件驱动,XmlReader) XmlSeria ...
- C# 二进制序列化(BinaryFormatter),Xml序列化(XmlSerializer),自己模拟写一个Xml序列化过程。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类
[.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类 本节导读:本节主要介绍通过序列 ...
- .NET中XML序列化的总结
[题外话] 以前虽然常用.NET中的序列化,但是常用的BinaryFormatter,也就是二进制文件的序列化,却鲜用XML的序列化.对于XML序列化,.NET中同样提供了一个非常方便的工具XmlSe ...
- XML序列化和反序列化
上篇总结了下JSON的序列化和反序列化,博园中大牛给了很多牛叉的评论,学习了不少. 不过在上篇中忘了把json序列化和反序列化的另外一种方式写上去了,这里做个简单的补充: Json篇:http://w ...
随机推荐
- 10、Hadoop组件启动方式和SSH无密码登陆
启动方式 一.各个组件逐一启动 hdfs: hadoop-daemon.sh start|stop namenode|datanode|secondnode yarn: yarn-demon.sh s ...
- LeetCode 358. Rearrange String k Distance Apart
原题链接在这里:https://leetcode.com/problems/rearrange-string-k-distance-apart/description/ 题目: Given a non ...
- 在Modelsim波形窗口复制信号
可以通过张贴复制变量名在Modelsim波形窗口复制信号.
- linux常用命名汇总:自用,持续更新
1.查看磁盘空间大小 df -hl 查看磁盘剩余空间 df -h 查看每个根路径的分区大小 du -sh [目录名] 返回该目录的大小 du -sm [文件夹] 返回该文件夹总M数 du -h [目录 ...
- hypermesh对msh文件或者cas文件重新命名边界
原视频下载地址: https://pan.baidu.com/s/1c1Thqm 密码: muhe
- crontab定时任务接入
# 查看 $ crontab -l # 创建 $ crontab -e # 每分钟输出一次当前时间 * * * * * echo `date` >> /demo.log # 查看定时 $ ...
- TICK/TIGK运维栈安装运行 docker【中】
InfluxDB docker search influxdb docker pull influxdb docker run -d -p 8086:8086 -v /var/lib/influxdb ...
- uniapp - 关于调试跨域
[] 1.右键Chrome图标 2.选中属性(R) 3.在目标(T) chrome.exe后添加 --disable-web-security --user-data-dir --allow-runn ...
- axios 文件下载代码 片段
<script type="text/javascript"> axios({ method:'post', url: 'url', // 最好qs.stringify ...
- C# System.Net.Mail.MailMessage 发邮件
C# System.Net.Mail.MailMessage 发邮件 上篇文化在哪个可以看到使用 System.Web.Mail.MailMessage 发邮件时会提示 ,提供用于构造电子邮件的属性和 ...