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
>
查看全文
相关阅读:
网络分析(二)定向与非定向
Flex 找不到html文件,不能自动生成html问题解决
常用的功能点记录
git常规操作命令整理
语境驱动测试7原则
探索式测试的问与答
测试建模:Google ACC
探索式测试:基于测程的测试管理(SessionBased Test Management)
用Excel展示SQL Server中的数据 (III): IronPython与自动化
在Ajax中使用Flash实现跨域数据读取
原文地址:https://www.cnblogs.com/RuiLei/p/647303.html
最新文章
如何设置IIS 6的应用程序池(4G内存)【转】
深入理解HTTP协议(转)
png做图
包含include 页面多出一个空格
如何处理提交页面是GB2312编码格式,接收页面是UTF8格式
新浪微博辅助工具总结
联合查询时需注意
此文件中的某些文本格式可能已经更改,因为它已经超出最多允许的字体数。关闭其他文档再试一次可能有用。
父子窗口传值
PDF转Word
热门文章
转:VB.net中 使文本框只能输入数字
vb.net打包基础
SaveFileDialog的用法
memoの关于Qt的一些用法记录
vim记录
我的vim配置相关
ArcGIS Server + SilverLight + NetWorkAnalyst 网络分析错误:routing error:error solving route,unable to find attribute invalid!
ArcGIS Server 用户权限设置问题
网络分析(一)数据要求
Win7中安装ArcGIS Desktop之Error1904解决方案
Copyright © 2011-2022 走看看