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
>
查看全文
相关阅读:
RubyConf的podcast
一篇很好的英语学习文章:一个孤独而封闭世界――英语口语
新浪和搜狐的读书频道
新想法:个性化的RSS
代码搜索:Koders
我看到的Web 2.0: 自组织的大众化参与
土豆网的后舍男孩挺搞笑的
可以给pdf加批注的软件VeryPDF PDF Editor
张海迪写的描写英语学习经验的书《美丽的英语》
Fowler出来推荐Rake了(基于Ruby的build工具)
原文地址:https://www.cnblogs.com/RuiLei/p/647303.html
最新文章
很不错的FreeRIDE!
博客园是否能学习blogbus的Tag功能?
Ning: 社会软件建造平台。
又见忽悠:别把UML举得太高——读《程序员》文章有感
把acrobat reader扔到太平洋,用小巧的foxit!
希望湖南卫视和更多的电视台能超过CCTV看超级女声有感!
欢迎加入Ruby中文邮件列表!
挺有新意的flash界面:http://www.dontclick.it/
不错的Haskell中文教程
Tim O'Reilly说web 2.0
热门文章
把闲置达95%的CPU时间贡献给www.worldcommunitygrid.org
rss阅读器对比:周博通和GreatNews
很有意思的函数型语言Haskell
财务会计教程(第8版)是很不错的书
head first design patterns这本书值得一读!
rss的普及需要一个容易理解的中文名字,叫“新闻源”如何?
播客:对Dave Thomas的访谈(Ruby Rails)
乱弹盗版
yahoo提供的新服务Rollyo: 专业化的搜索
一本让人乐观开朗的书<做个喜悦的人念处今论>
Copyright © 2011-2022 走看看