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 ...
随机推荐
- The database returned no natively generated identity value错误解决方案
原因:hibernate项目中在学生表的配置文件中: <id name="studentno" column="studentno"> <ge ...
- proxysql 学习一 proxysql docker 运行试用
proxysql 是一个比较强大的mysql proxy 服务,支持动态mysql 实例调整,查询重写,查询cache,监控,数据镜像,读写分离 以及ha,最近已经发布了2.0 ,很值得试用下 环境准 ...
- CSS链接伪类:超链接的状态
一.状态: a:link{属性:值;} 链接默认状态 a:visited{属性:值;} 链接访问之后的状态 a:hover{属性:值;} 鼠标放到链接上显示的状态 a:active{属性:值;} 链接 ...
- CF #365 DIV2 D Mishka and Interesting sum 区间异或+线段树
D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...
- linux命令之------Wc命令(word count)
Wc命令(word count) 1)作用:用于计算字数: 2)-c或--bytes或--chars只显示Bytes数: 3)-l和—line显示行号: 4)-w或words只显示字数: 5)--he ...
- 【luoguP5091】【模板】欧拉定理
题目链接 欧拉定理: 当\(a\),\(m\)互质时,\(a^{\phi(m)}\equiv 1 (mod ~ m)\) 扩展欧拉定理: 当\(B>\phi(m)\)时,\(a^B\equiv ...
- 【洛谷P5596】【XR-4】题
solution \(y^2-x^2=ax+b\) \(y^2=x^2+ax+b\) 当\(x^2+ax+b\)为完全平方式时\(Ans=inf\) \(x \leq y\) 不妨令 \(y=x+t\ ...
- js如何将汉字转化为拼音
github地址,上面有封装好的转换工具:https://github.com/sxei/pinyinjs 里面有几个库,根据功能,库的文件大小也不一样,可以根据需求去引入使用. 里面封装好了方法: ...
- Kali linux 2018 安装 Fluxion
本人是在VMware 12下安装 Kali linux 2018.2版本 安装完成后 用命令行运行更新 apt-get update apt-get full-upgrade 更新所有组件. ...
- Authenticator App 两步验证会不会造成亚马逊账号关联?
今天听人说,因为用Authenticator App做亚马逊两步验证造成了帐号关联…… 我给大家解释一下Authenticator的实现原理,作为计算机专业科班出身的我,此次从各方面了解并经过自己亲测 ...