xml写入

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Reflection;
usingSystem.IO;
usingSystem.Xml;
 
 
namespace_2015._4._14p.m
{
classProgram
{
staticvoidMain(string[]args)
{

//创建一个xmldocument(文件/文档)对象
XmlDocumentdbXml1=newXmlDocument();
//创建XML头,也就是声明declaration(宣布)
XmlDeclarationdec=dbXml1.CreateXmlDeclaration("1.0",null,null);
//告诉xmldocument对象,这个dec是他的
dbXml1.AppendChild(dec);
//创建根节点(xml规定只有一个
XmlElementbookSysNode=dbXml1.CreateElement("BOOKSYS1111");
 
dbXml1.AppendChild(bookSysNode);
//把其写入xml
dbXml1.Save(GetDbpath());
}
 
publicstaticStringGetDbpath()
{
//获取当前exe文件的路径
StringcurrExePath=Assembly.GetExecutingAssembly().Location;

//获取文件夹的名字例如路径c:\123\1.txt会得到c:\123
StringcurrentDir=Path.GetDirectoryName(currExePath);
//将路径和xml文件名组合在一起
StringcurrDbPath=Path.Combine(currentDir,"booksys.xml");
returncurrDbPath;
}
 
}
}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念