惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
N
News and Events Feed by Topic
量子位
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
J
Java Code Geeks
Schneier on Security
Schneier on Security
Google Online Security Blog
Google Online Security Blog
TaoSecurity Blog
TaoSecurity Blog
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
博客园 - 聂微东
T
Tor Project blog
博客园 - Franky
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
罗磊的独立博客
博客园_首页
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
腾讯CDC
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
博客园 - 【当耐特】
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
博客园 - 司徒正美
AWS News Blog
AWS News Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
G
GRAHAM CLULEY
V
V2EX
L
LINUX DO - 最新话题
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家

博客园 - YQM

NUnit单元测试属性介绍 C#静态构造函数 没有使用lock的Singleton How to serialize and deserialize using C# .NET - YQM Javascript调用web service 简单的英语不简单 我们应该怎样去学习和工作--写给自己 扩展方法 使用反射-动态创建对象及调用对象方法 使用XmlReader类 知道做什么而不是怎样做(摘抄) 生活15点,要记住! 设计模式之Command模式 使用javascript动态添加和删除table的行和列 Generate unique strings and numbers in C#(生成一个唯一的字符串和数值) Some notes Localization in ASP.NET 2.0 ASP.NET 2.0: Playing a bit with GridView "Sort Grouping" 通过TryParse来检验和转换数据类型
使用XmlWriter对象
YQM · 2008-07-06 · via 博客园 - YQM

XmlWriter类可以把XML写入一个流,文件,StringBuilder,TextWriter或另一个XmlWriter对象中。代码:

 1XmlWriterSettings settings = new XmlWriterSettings();
 2//是否缩进
 3settings.Indent = true;
 4//属性是否在新行
 5settings.NewLineOnAttributes = true;
 6XmlWriter writer = XmlWriter.Create("booknew.xml", settings);
 7writer.WriteStartDocument();
 8writer.WriteStartElement("book");
 9writer.WriteAttributeString("genre""Mystery");
10writer.WriteAttributeString("publicationdate""2001");
11writer.WriteAttributeString("ISBN""123456789");
12writer.WriteElementString("title""Case of the Missing Cookie");
13writer.WriteStartElement("author");
14writer.WriteElementString("name""Cookie Monster");
15writer.WriteEndElement();
16writer.WriteElementString("price""9.99");
17writer.WriteEndElement();
18writer.WriteEndDocument();
19writer.Flush();
20writer.Close();

运行后生成文件booknew.xml:

 1<?xml version="1.0" encoding="utf-8"?>
 2<book
 3  genre="Mystery"
 4  publicationdate="2001"
 5  ISBN="123456789">
 6  <title>Case of the Missing Cookie</title>
 7  <author>
 8    <name>Cookie Monster</name>
 9  </author>
10  <price>9.99</price>
11</book>