zoukankan
html css js c++ java
XmlDocument的应用创建Xml模板
protected
void
btnCreate_Click(
object
sender, EventArgs e)
{
//
定义XMLDocument
XmlDocument xmlDocument
=
new
XmlDocument();
//
定义XML文档头文件
XmlDeclaration xmlDeclaration
=
xmlDocument.CreateXmlDeclaration(
"
1.0
"
,
"
utf-8
"
,
null
);
//
增加XML文档头
xmlDocument.AppendChild(xmlDeclaration);
//
定义XML的根
XmlElement xmlRoot
=
xmlDocument.CreateElement(
"
Roots
"
);
//
添加XML的根
xmlDocument.AppendChild(xmlRoot);
//
添加根的属性
xmlRoot.SetAttribute(
"
RootAttribute
"
,
"
Value
"
);
//
修改根属性的值
xmlRoot.GetAttributeNode(
"
RootAttribute
"
).Value
=
"
FixValue
"
;
//
定义节点
XmlNode xmlElement;
//
循环创建节点
for
(
int
i
=
0
; i
<
2
; i
++
)
{
//
创建XML根的节点
xmlElement
=
xmlDocument.CreateElement(
"
Element
"
);
//
XML需要的属性列表
foreach
(KeyValuePair
<
String, String
>
keyValuePair
in
NameValueDictionary())
{
//
定义XML根的节点中的属性
XmlAttribute oneAttribute
=
xmlDocument.CreateAttribute(keyValuePair.Key);
oneAttribute.Value
=
keyValuePair.Value;
XmlAttribute secAttribute
=
xmlDocument.CreateAttribute(keyValuePair.Key);
secAttribute.Value
=
keyValuePair.Value;
//
添加XML根的节点中的属性
xmlElement.Attributes.Append(oneAttribute);
xmlElement.Attributes.Append(secAttribute);
//
添加XML根的节点
xmlRoot.AppendChild(xmlElement);
}
}
//
保存XML文档
xmlDocument.Save(Server.MapPath(
"
OutDocument.XML
"
));
}
//
XML需要的属性列表
private
Dictionary
<
String, String
>
NameValueDictionary()
{
Dictionary
<
String, String
>
nameValueDictionary
=
new
Dictionary
<
String, String
>
();
nameValueDictionary.Add(
"
AttributeOne
"
,
"
One
"
);
nameValueDictionary.Add(
"
AttributeSec
"
,
"
Second
"
);
return
nameValueDictionary;
}
生成的XML模块
<?
xml version="1.0" encoding="utf-8"
?>
<
Roots
RootAttribute
="FixValue"
>
<
Element
AttributeOne
="One"
AttributeSec
="Second"
/>
<
Element
AttributeOne
="One"
AttributeSec
="Second"
/>
</
Roots
>
查看全文
相关阅读:
数据持久化的复习
iOS: 消息通信中的Notification&KVO
iOS 证书与签名 解惑详解
数据持久化 技术比较
iOS开发拓展篇-XMPP简单介绍
iOS block并发
Xcode把应用程序打包成ipa
谈谈用SQLite和FMDB而不用Core Data
cannot use the same dataset for report.dataset and page.dataset
cxGRID中的字段怎么能以0.00的格式显示
原文地址:https://www.cnblogs.com/RuiLei/p/647303.html
最新文章
HTML中a标签的锚点
java正则表达式
eclipse中设置新建jsp文件的编码格式
springJDBC的几种方法
spring通知的注解
spring的几个通知(前置、后置、环绕、异常、最终)
spring的AOP编程
spring半自动代理
漫谈Word2vec之skip-gram模型
Python---哈夫曼树---Huffman Tree
热门文章
Python标准库——collections模块的Counter类
Python List extend()方法
pytorch系列 -- 9 pytorch nn.init 中实现的初始化函数 uniform, normal, const, Xavier, He initialization
使用 Pytorch 实现 skip-gram 的 word2vec
深度学总结:skip-gram pytorch实现
PyTorch的十七个损失函数
pytorch之Tensor与Variable的区别
torch.nn.Embedding理解
ios 清理缓存
代码 调节屏幕亮度
Copyright © 2011-2022 走看看