c# 创建xml

Posted 旗木卡卡西西

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);

以上是关于c# 创建xml的主要内容,如果未能解决你的问题,请参考以下文章