C# 写XML文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace 写xml
{
class Program
{
static void Main(string[] args)
{
string filename = "C:\\Users\\CMS01\\Desktop\\tool.xml";//文件路径
XElement rootEle = new XElement("Project",
new XAttribute("Version", "1.0"));//根节点
XElement propertyEle = new XElement("PropertyGroup");//子节点
for(int i = 0;i<10;i++)
{
propertyEle.Add(new XElement("OutputName", "测试的字符"+i));
}
rootEle.Add(propertyEle);//将子节点加入到根节点
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", null), rootEle);//给xml流加个头
xDoc.Save(filename);//将xDoc保存为filename这个路径的文档
}
}
}
xml文件效果:
本文作者:cloud-sword
本文链接:https://www.cnblogs.com/cloud-sword/p/16542613.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步