xml创建节点(根节点、子节点)

栏目: 编程语言 · XML · 发布时间: 8年前

内容简介:声明、创建、创建根节点、添加Books的子节点最后保存文档(如果已经存在该文件,则更新之;如果没有,则创建该文件),不会的朋友可以了解下哈
复制代码 代码如下:

protected void Button1_Click(object sender, EventArgs e)//创建xml
{
//声明
XmlDocument x = new XmlDocument();
//创建
XmlDeclaration xd = x.CreateXmlDeclaration("1.0", "GB2312", null);
x.AppendChild(xd);
//创建根节点
XmlElement element = x.CreateElement("Books");
x.AppendChild(element);
//添加Books的子节点
XmlNode book = x.CreateElement("Book");
//给Book添加元素
XmlElement bookname = x.CreateElement("书名");
bookname.InnerText = "三国";
//逐级添加到节点上
book.AppendChild(bookname);
element.AppendChild(book);
x.AppendChild(element);
//保存文档(如果已经存在该文件,则更新之;如果没有,则创建该文件)
x.Save(@"F:/Books.xml");

}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Discrete Mathematics and Its Applications

Discrete Mathematics and Its Applications

Kenneth H Rosen / McGraw-Hill Science/Engineering/Math / 2003-04-22 / USD 132.81

Discrete Mathematics and its Applications is a focused introduction to the primary themes in a discrete mathematics course, as introduced through extensive applications, expansive discussion, and deta......一起来看看 《Discrete Mathematics and Its Applications》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具