C#创建生成XML文件
来源:互联网 发布:mac miller身高 编辑:程序博客网 时间:2024/05/22 09:25
//生成 自定义地点区域 xml格式文件 XmlDocument docLocation = new XmlDocument(); XmlDeclaration nodeDeclarLocation = docLocation.CreateXmlDeclaration("1.0", "UTF-8", null); docLocation.AppendChild(nodeDeclarLocation); //生成 vacationSiteList XmlElement vacationSiteList = docLocation.CreateElement("vacationSiteList"); docLocation.AppendChild(vacationSiteList);//生成 site XmlElement site = docLocation.CreateElement("site"); vacationSiteList.AppendChild(site);//生成 siteID XmlElement siteID = docLocation.CreateElement("siteID"); siteID.InnerXml = "1"; site.AppendChild(siteID); //生成 siteName XmlElement siteName = docLocation.CreateElement("siteName"); siteName.InnerXml ="上海" site.AppendChild(siteName); //文件地址 string txtPath_sites = ServerPath_index + "\\site.xml"; //写文件 docLocation.Save(txtPath_sites); /// <summary>/// xml结点内容格式化 防止xml文件内含有特殊字符/// </summary>/// <param name="inertext">内容</param>/// <returns></returns> public static string CDateXmlInnerXml(string inertext){ inertext = inertext.Replace("", string.Empty); inertext = "<![CDATA[" + inertext + "]]>"; return inertext;}