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
>
查看全文
相关阅读:
求二叉树中最远两节点距离
计算机系统
webdriver高级应用- 无人工干预地自动下载某个文件
webdriver高级应用- 改变一个页面对象的属性值
webdriver高级应用- 在ajax方式产生的浮动框中,单击选择包含某个关键字的选项
webdriver高级应用-js操作滚动条
webdriver高级应用-使用JavaScript操作页面元素
Selenium WebDriver- 指定页面加载时间
Selenium WebDriver- 操作浏览器的cookie
Selenium WebDriver- 操作JavaScript的prompt弹窗(使用率低)
原文地址:https://www.cnblogs.com/RuiLei/p/647303.html
最新文章
CentOS 7 安装 Oracle 11.2.0.4
multipath配置详细参考
vuex 我在项目中是这样统一接管请求的
HTTP详解
移动端input“输入框”常见问题及解决方法
HTML5新特性 Web Workers 实现多线程
Vue keep-alive总结
vue虚拟DOM源码学习-vnode的挂载和更新流程
Vue + webpack 项目配置化、接口请求统一管理
Object对象的浅拷贝与深拷贝方法详解
热门文章
vue组件通信&&v兄弟组件通信eventbus遇到的问题(多次触发、第一次不触发)
前端常见跨域解决方案
3、动态规划问题中的最优路径保存与输出
2、矩阵链乘的优化
最长公共子序列
15-1有向无环图中的最长路径
15-2求最大回文的长度
最优化子数组问题
硬币找零&&爬楼梯&&猴子摘香蕉
装配线问题
Copyright © 2011-2022 走看看