//兼容做法
XDocument xdoc = new XDocument();
//配置头文件【不写也行】
//xdoc.Declaration = new XDeclaration("1.0", "utf-8", null);
//写入节点名称
XElement xe = new XElement("root");
//写入节点内容
xe.Value = "节点内容";
//写入节点属性
XAttribute xa = new XAttribute("name","张三");
//节点属性写入节点
xe.Add(xa);
//节点写入xdoc
xdoc.Add(xe);
//保存xml文件
xdoc.Save("2.xml");
使用Linq创建xml文件
最新推荐文章于 2021-12-20 21:41:24 发布