您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天小编给大家分享的是创建xml文件的代码,很多人都不太了解,今天小编为了让大家更加了解创建xml文件的方法,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。
/// <summary>
/// 创建一个xml文件
/// </summary>
/// <param name="fileName">文件名字</param>
private void createXmlDoc(string fileName)
{
string row= System.Environment.NewLine;
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xde ;//表示 XML 声明节点:<?xml version='1.0'...?>
xde = xmlDoc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);//verson:1.0 encoding:utf-8 standalone:yes(表示独立的,不依赖别的文件)
xmlDoc.AppendChild(xde);
XmlElement root = xmlDoc.CreateElement("BOOKS");
root.SetAttribute("name", "根级元素");
xmlDoc.AppendChild(root);
XmlElement node1 = xmlDoc.CreateElement("BOOK");
root.AppendChild(node1);
XmlElement node11 = xmlDoc.CreateElement("AUTHOR");
node11.InnerText = "XMROOM";
node1.AppendChild(node11);
XmlElement node12 = xmlDoc.CreateElement("NAME");
node12.InnerText = "编程你最爱";
node1.AppendChild(node12);
XmlElement node13 = xmlDoc.CreateElement("TIME");
node13.InnerText = "2013-11-20";
node1.AppendChild(node13);
XmlElement node14 = xmlDoc.CreateElement("COPYRIGHT");
node14.InnerText = "XMROOM";
node1.AppendChild(node14);
string path = Server.MapPath("Xml\\") + fileName + ".xml";
if (File.Exists(path))
{
File.Delete(path);
}
xmlDoc.Save(path);
}以上就是创建xml文件的代码的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注亿速云行业资讯频道哦!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。