加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml写入

发布时间:2020-12-16 09:11:38 所属栏目:百科 来源:网络整理
导读:using System ; using System . Collections . Generic ; using System . Linq ; using System . Text ; using System . Threading . Tasks ; using System . Reflection ; using System . IO ; using System . Xml ; namespace _2015 . _4 . _14p . m { cla
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:1231.txt会得到c:123
StringcurrentDir=Path.GetDirectoryName(currExePath);
//将路径和xml文件名组合在一起
StringcurrDbPath=Path.Combine(currentDir,"booksys.xml");
returncurrDbPath;
}
 
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读