c# 创建xml

XmlDocument xmldoc = new XmlDocument();
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0", "utf-8", null);
xmldoc.AppendChild(xmldecl);

//加入一个根元素 root
XmlElement xmlelem = xmldoc.CreateElement("", "root", "");
xmldoc.AppendChild(xmlelem);

XmlNode root = xmldoc.SelectSingleNode("root");

XmlElement sourceSystem = xmldoc.CreateElement("sourceSystem");//创建节点
sourceSystem.InnerText = "AVID";
root.AppendChild(sourceSystem);

XmlElement fileName = xmldoc.CreateElement("fileName");//创建节点
fileName.InnerText = ti.ProgramTitle;
root.AppendChild(fileName);

XmlElement filePath = xmldoc.CreateElement("filePath");//创建节点
filePath.InnerText = ti.TranscodeFileName;
root.AppendChild(fileName);

XmlElement fileMd5 = xmldoc.CreateElement("fileMd5");//创建节点
root.AppendChild(fileMd5);

string path ="d:\1.xml";

xmldoc.save(path);

欲成为海洋大师,必知晓海中每一滴水的真名!
原文地址:https://www.cnblogs.com/ssjsk/p/5499799.html