XML怎么写入数据

前端之家收集整理的这篇文章主要介绍了XML怎么写入数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Load调用方法 Create_Xml(Create_XML_Name());

public static string filePath = Application.StartupPath + "/XML/"; //存放XML文件的地址,Bin/Debug/XML文件

private string Create_XML_Name()
{
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
return (filePath + "文件名称" + ".xml");
}

private static void Create_Xml(string xmlPath)
{
XmlTextWriter writer = new XmlTextWriter(xmlPath,null);

//使用自动缩进便于阅读
writer.Formatting = Formatting.Indented;

writer.WriteStartElement("Manifest"); //写入根元素Manifest

writer.WriteStartElement("Head"); //打开根元素Head,并书写开始标签
writer.WriteElementString("MessageID","编号"); //编号
writer.WriteElementString("DateTime",""); //时间
writer.WriteElementString("Version",""); //版本号
writer.WriteEndElement(); //关闭根元素Head,并书写结束标签

writer.WriteStartElement("Declaration");//写入根元素Declaration

writer.WriteEndElement(); //关闭根元素Declaration

writer.WriteEndElement(); //关闭根元素Manifest
writer.Close();

}

原文链接:https://www.f2er.com/xml/299998.html

猜你在找的XML相关文章