创建xml文件
public void CreateXmlFile(string LayoutFileXml,int id)
{
XmlDocument xmlDoc = new XmlDocument();
//创建类型声明节点
XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
xmlDoc.AppendChild(node);
//创建根节点
XmlNode root = xmlDoc.CreateElement("LayoutXml");
xmlDoc.AppendChild(root);
//创建子节点
CreateNode(xmlDoc, root, "TableXML" + id, null);
try
{
//保存xml
xmlDoc.Save(LayoutFileXml);
}
catch (Exception e)
{
//显示错误信息
Console.WriteLine(e.Message);
}
//CreateNode 事件方法
public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
{
XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
node.InnerText = value;
parentNode.AppendChild(node);
}
网友评论