xml写入

前端之家收集整理的这篇文章主要介绍了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;
}
 
}
}
@H_786_301@ 原文链接:https://www.f2er.com/xml/296913.html

猜你在找的XML相关文章