今天写代码,添加几条XML记录,总感觉写那几条重复的语句很不爽,就写了这个方法
代码如下:
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1327ab569c1ae82736693a50b8e33378.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1327ab569c1ae82736693a50b8e33378.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/7ff8d92cded7e0ce15e7ca1acc870052.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/717446ca04a6125dc5b6b54e0fa14ab4.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
方法有5个参数,下面介绍下这5个参数:
参数一 xmlPath , string型 , 代表XML文档的相对路径
参数二 rootElement , string型 , 代表XML文档的根元素
参数三 rootPoint , string型 , 代表XML文档每条记录的根元素
参数四 elementNum , int型 , 代表每条记录的子元素数量
参数五 addInfo , 数组型 , 代表的是一个二维数组,用来存储每条记录的信息,包括元素名和元素的值
下面给个例子:
用来演示的XML文档结构如下:
<?xml version="1.0" encoding="utf-8"?>
<ProgramboyGuestbook>
<ly>
<Gcontent>这是用来演示插入XML记录方法的XML文档,我的相对路径是Data/test.xml</Gcontent>
<Gname>孤鸿</Gname>
<Gtime>2006-9-18 8:49:23</Gtime>
<Gweb>http://www.programboy.com</Gweb>
</ly>
</ProgramboyGuestbook>
下面我们来调用插入方法,实现插入操作:
this.addXmlInfo("Data/test.xml","ProgramboyGuestbook","ly",4,new string[,] {{"Gcontent",theContent},{"Gname",theName},{"Gtime",theTime},{"Gweb",theWeb}});
孤鸿原创,转载请注明出处,谢谢.本文源出处:程序男孩论坛(http://bbs.programboy.com)