/// <summary> /// 将XML字符串写入到XML文件 /// </summary> /// <param name="strXML"></param> private int WriteStrToXML(string strXmlName, string strXML) { try { string filepath = System.Web.HttpContext.Current.Server.MapPath("~/CatXML"); if (!Directory.Exists(filepath)) Directory.CreateDirectory(filepath); filepath = filepath + "/" + DateTime.Now.ToString("yyyy-MM-ddHHmmss") + strXmlName + ".XML"; XmlDocument xdoc = new XmlDocument(); xdoc.AppendChild(xdoc.CreateXmlDeclaration("1.0", "UTF-8", null));//xml文件头 xdoc.LoadXml(strXML); xdoc.Save(filepath); return 0; } catch (Exception) { return -1; } }