当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.Save方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.Save方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Save方法的具体用法?C# XmlDocument.Save怎么用?C# XmlDocument.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExistAccessToken

 /// 获取token,如果存在且没过期,则直接取token
 /// <summary>
 /// 获取token,如果存在且没过期,则直接取token
 /// </summary>
 /// <returns></returns>
 public static string GetExistAccessToken()
 {
     // 读取XML文件中的数据
     string filepath = System.Web.HttpContext.Current.Server.MapPath("/XMLToken.xml");
     FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     StreamReader str = new StreamReader(fs, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     str.Close();
     str.Dispose();
     fs.Close();
     fs.Dispose();
     string Token = xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText;
     DateTime AccessTokenExpires = Convert.ToDateTime(xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText);
     //如果token过期,则重新获取token
     if (DateTime.Now >= AccessTokenExpires)
     {
         AccessToken mode = Getaccess();
         //将token存到xml文件中,全局缓存
         xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText = mode.access_token;
         DateTime _AccessTokenExpires = DateTime.Now.AddSeconds(mode.expires_in);
         xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText = _AccessTokenExpires.ToString();
         xml.Save(filepath);
         Token = mode.access_token;
     }
     return Token;
 }
开发者ID:shinygang,项目名称:Wechat-JSSDK,代码行数:32,代码来源:JSSDK.cs

示例2: OverWriting

        private bool OverWriting() {
        //private async Task<bool> OverWriting() {
            if (ListingQueue.Any()) {
                XmlDocument xmlDoc;
                XmlElement xmlEle;
                XmlNode newNode;

                xmlDoc = new XmlDocument();
                xmlDoc.Load("ImageData.xml"); // XML문서 로딩

                newNode = xmlDoc.SelectSingleNode("Images"); // 추가할 부모 Node 찾기
                xmlEle = xmlDoc.CreateElement("Image");
                newNode.AppendChild(xmlEle);
                newNode = newNode.LastChild;
                xmlEle = xmlDoc.CreateElement("ImagePath"); // 추가할 Node 생성
                xmlEle.InnerText = ListingQueue.Peek();
                ListingQueue.Dequeue();
                newNode.AppendChild(xmlEle); // 위에서 찾은 부모 Node에 자식 노드로 추가..

                xmlDoc.Save("ImageData.xml"); // XML문서 저장..
                xmlDoc = null;

                return true;
            }
            return false;
        }
开发者ID:InhoChoi,项目名称:KICOM,代码行数:26,代码来源:WriteImageList.cs

示例3: Save

        public void Save(string path)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("Resources");
            doc.AppendChild(root);

            XmlElement sheetsElem = doc.CreateElement("SpriteSheets");
            foreach (KeyValuePair<string, SpriteSheet> pair in SpriteSheets)
            {
                XmlElement elem = doc.CreateElement(pair.Key);
                pair.Value.Save(doc, elem);
                sheetsElem.AppendChild(elem);
            }
            root.AppendChild(sheetsElem);

            XmlElement spritesElem = doc.CreateElement("Sprites");
            foreach (KeyValuePair<string, Sprite> pair in Sprites)
            {
                XmlElement elem = doc.CreateElement(pair.Key);
                pair.Value.Save(doc, elem);
                spritesElem.AppendChild(elem);
            }
            root.AppendChild(spritesElem);

            XmlElement animsElem = doc.CreateElement("Animations");
            foreach (KeyValuePair<string, Animation> pair in Animations)
            {
                XmlElement elem = doc.CreateElement(pair.Key);
                pair.Value.Save(doc, elem);
                animsElem.AppendChild(elem);
            }
            root.AppendChild(animsElem);

            doc.Save(path);
        }
开发者ID:BlaisePascalSi,项目名称:PokeSi,代码行数:35,代码来源:Resources.cs

示例4: updateCartFile

        public void updateCartFile(List<CartObject> newCartObj)
        {
            bool found = false;

            string cartFile = "C:\\Users\\Kiran\\Desktop\\cart.xml";

            if (!File.Exists(cartFile))
            {
                XmlTextWriter xWriter = new XmlTextWriter(cartFile, Encoding.UTF8);
                xWriter.Formatting = Formatting.Indented;
                xWriter.WriteStartElement("carts");
                xWriter.WriteStartElement("cart");
                xWriter.WriteAttributeString("emailId", Session["emailId"].ToString());
                xWriter.Close();
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(cartFile);
            foreach (CartObject cartItem in newCartObj)
            {
                foreach (XmlNode xNode in doc.SelectNodes("carts"))
                {
                    XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (cartNode.Attributes["emailId"].InnerText == Session["emailId"].ToString())
                    {
                        found = true;
                        XmlNode bookNode = doc.CreateElement("book");
                        XmlNode nameNode = doc.CreateElement("name");
                        nameNode.InnerText = cartItem.itemName;
                        XmlNode priceNode = doc.CreateElement("price");
                        priceNode.InnerText = cartItem.itemPrice.ToString();
                        XmlNode quantityNode = doc.CreateElement("quantity");
                        quantityNode.InnerText = "1";
                        bookNode.AppendChild(nameNode);
                        bookNode.AppendChild(priceNode);
                        bookNode.AppendChild(quantityNode);
                        cartNode.AppendChild(bookNode);
                    }
                }
                if(!found)
                  {
                        XmlNode cartNode = doc.CreateElement("cart");
                        cartNode.Attributes["emailId"].InnerText = Session["emailId"].ToString();
                        XmlNode bookNode = doc.CreateElement("book");
                        XmlNode nameNode = doc.CreateElement("name");
                        nameNode.InnerText = cartItem.itemName;
                        XmlNode priceNode = doc.CreateElement("price");
                        priceNode.InnerText = cartItem.itemPrice.ToString();
                        XmlNode quantityNode = doc.CreateElement("quantity");
                        quantityNode.InnerText = "1";
                        bookNode.AppendChild(nameNode);
                        bookNode.AppendChild(priceNode);
                        bookNode.AppendChild(quantityNode);
                        cartNode.AppendChild(bookNode);
                        doc.DocumentElement.AppendChild(cartNode);

                  }
                }
            doc.Save(cartFile);
        }
开发者ID:kiranprakash154,项目名称:SellingBooks,代码行数:60,代码来源:WelcomePage.aspx.cs

示例5: UpdateSagaXMLFile

        public static string UpdateSagaXMLFile(ref DataTable _XMLDt, string XMLpath)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(XMLpath);

                XmlNode xmlnode = xmldoc.DocumentElement.ChildNodes[0];
                xmlnode["ODBCDriverName"].InnerText = _XMLDt.Rows[0]["ODBCDriverName"].ToString();
                xmlnode["HostName"].InnerText = _XMLDt.Rows[0]["HostName"].ToString();
                xmlnode["ServerName"].InnerText = _XMLDt.Rows[0]["ServerName"].ToString();
                xmlnode["ServiceName"].InnerText = _XMLDt.Rows[0]["ServiceName"].ToString();
                xmlnode["Protocol"].InnerText = _XMLDt.Rows[0]["Protocol"].ToString();
                xmlnode["DatabaseName"].InnerText = _XMLDt.Rows[0]["DatabaseName"].ToString();
                xmlnode["UserId"].InnerText = _XMLDt.Rows[0]["UserId"].ToString();
                xmlnode["Password"].InnerText = _XMLDt.Rows[0]["Password"].ToString();
                xmlnode["ClientLocale"].InnerText = _XMLDt.Rows[0]["ClientLocale"].ToString();
                xmlnode["DatabaseLocale"].InnerText = _XMLDt.Rows[0]["DatabaseLocale"].ToString();

                xmldoc.Save(XMLpath);

                return "";
            }
            catch (Exception err)
            {
                return err.Message;
            }
        }
开发者ID:safaintegrated,项目名称:asm,代码行数:28,代码来源:XML.cs

示例6: Continue_Click

 private void Continue_Click(object sender, RoutedEventArgs e)
 {
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\App.config");
     XmlNode appSettingsNode = xmlDoc.SelectSingleNode("configuration/appSettings");
     foreach (XmlNode childNode in appSettingsNode)
     {
         string selection = childNode.Attributes["key"].Value;
         switch (selection)
         {
             case "MagicWebPath":
                 childNode.Attributes["value"].Value = webPathBox.Text;
                 break;
             case "InputPath":
                 childNode.Attributes["value"].Value = inputPathBox.Text;
                 break;
             case "OutputPath":
                 childNode.Attributes["value"].Value = outputPathBox.Text;
                 break;
             default:
                 break;
         }
     }
     xmlDoc.Save(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\App.config");
     xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
 }
开发者ID:bmcc91,项目名称:Testing-WithDeletes,代码行数:26,代码来源:Options.xaml.cs

示例7: GenerateSettingsFile

        public void GenerateSettingsFile(WorkSettings settings)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.AppendChild(xmlDoc.CreateElement("PartCoverSettings"));
            if (settings.TargetPath != null) AppendValue(xmlDoc.DocumentElement, "Target", settings.TargetPath);
            if (settings.TargetWorkingDir != null) AppendValue(xmlDoc.DocumentElement, "TargetWorkDir", settings.TargetWorkingDir);
            if (settings.TargetArgs != null) AppendValue(xmlDoc.DocumentElement, "TargetArgs", settings.TargetArgs);
            if (settings.LogLevel > 0)
                AppendValue(xmlDoc.DocumentElement, "LogLevel", settings.LogLevel.ToString(CultureInfo.InvariantCulture));
            if (settings.SettingsFile != null) AppendValue(xmlDoc.DocumentElement, "Output", settings.SettingsFile);
            if (settings.PrintLongHelp)
                AppendValue(xmlDoc.DocumentElement, "ShowHelp", settings.PrintLongHelp.ToString(CultureInfo.InvariantCulture));
            if (settings.PrintVersion)
                AppendValue(xmlDoc.DocumentElement, "ShowVersion", settings.PrintVersion.ToString(CultureInfo.InvariantCulture));

            foreach (string item in settings.IncludeItems) AppendValue(xmlDoc.DocumentElement, "Rule", "+" + item);
            foreach (string item in settings.ExcludeItems) AppendValue(xmlDoc.DocumentElement, "Rule", "-" + item);

            try
            {
                if ("console".Equals(settings.GenerateSettingsFileName, StringComparison.InvariantCulture))
                    xmlDoc.Save(Console.Out);
                else
                    xmlDoc.Save(settings.GenerateSettingsFileName);
            }
            catch (Exception ex)
            {
                throw new SettingsException("Cannot write settings (" + ex.Message + ")");
            }
        }
开发者ID:killbug2004,项目名称:partcover-fork,代码行数:30,代码来源:WorkSettingsWriter.cs

示例8: WriteFile

        public static void WriteFile()
        {
            string configPath = KEY_CHANGER_FOLD + "/" + KEY_CHANGER_CONFIG_FILE + ".xml";
            XmlDocument xmlDoc = new XmlDocument();
            if (!File.Exists(configPath))
            {
                XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(INIT_VERSION_STR, INIT_ENCODING_STR, null);
                xmlDoc.AppendChild(dec);
                XmlElement rootInit = xmlDoc.CreateElement(DOC_ROOT_STR);
                xmlDoc.AppendChild(rootInit);
                xmlDoc.Save(configPath);
            }
            else
            {
                xmlDoc.Load(configPath);
            }
            XmlNode root = xmlDoc.SelectSingleNode(DOC_ROOT_STR);
            root.RemoveAll();

            foreach (KeyChangeItem item in KeyChangeManager.Instance.KeyChangeItemCollection)
            {
                WriteItem(item, ref xmlDoc, ref root);
            }
            xmlDoc.Save(configPath);
        }
开发者ID:tuyiherizon,项目名称:TableModifier,代码行数:25,代码来源:RWFile.cs

示例9: RecordAgent

        public void RecordAgent()
        {
            #region CLIENT RECORD

            if (!File.Exists(Generate.xmlPath))
                return;

            XmlDocument xmld = new XmlDocument();
            try { xmld.Load(Generate.xmlPath); }
            catch { Thread.Sleep(50); xmld.Load(Generate.xmlPath); }
            foreach (XmlElement xmle in xmld.GetElementsByTagName("clients"))
            {
                Coming c = new Coming();
                c.id = xmle["id"].InnerText;
                c.lep = xmle["lep"].InnerText;
                c.macAddress = xmle["macAddress"].InnerText;
                c.licence = xmle["licence"].InnerText;
                c.Session = Convert.ToInt32(xmle["Session"].InnerText);
                c.port = Convert.ToInt32(xmle["port"].InnerText);
                c.Address = xmle["Address"].InnerText;
                c.cep = new IPEndPoint(IPAddress.Parse(c.Address), c.port);

                Agent.clients.Add(c.id, c);
            }
            try { xmld.Save(Generate.xmlPath); }
            catch { Thread.Sleep(50); xmld.Save(Generate.xmlPath); }

            Generate.isFirst = false;
            ("SERVER WORKING FIRST TIME & TRANSFERRED XML DATA TO Agent.clients").p2pDEBUG();
            #endregion
        }
开发者ID:kztao,项目名称:NaT-Traversal-UDP-Hole-punch,代码行数:31,代码来源:Recording.cs

示例10: F_AddKey

 // Methods
 public static void F_AddKey(string i_StrKey, string i_StrValue)
 {
     if (!F_KeyExists(i_StrKey))
     {
         throw new ArgumentNullException("Key", "<" + i_StrKey + "> does not exist in the configuration. Update failed.");
     }
     XmlDocument document = new XmlDocument();
     document.Load(pathConfig);
     XmlNode node = document.SelectSingleNode(singleNote);
     try
     {
         if (node != null)
         {
             XmlNode newChild = node.FirstChild.Clone();
             if (newChild.Attributes != null)
             {
                 newChild.Attributes["key"].Value = i_StrKey;
                 newChild.Attributes["value"].Value = i_StrValue;
             }
             node.AppendChild(newChild);
         }
         document.Save(pathConfig);
         document.Save(ConfigurationFile);
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
开发者ID:cuongpv88,项目名称:work,代码行数:30,代码来源:SettingConfiguration.cs

示例11: DefaultSettings

		public DefaultSettings()
		{
			xmlDoc = new XmlDocument();

			Assembly asmblyMyGen = System.Reflection.Assembly.GetAssembly(typeof(NewAbout));
			string version = asmblyMyGen.GetName().Version.ToString();

			try
			{
				xmlDoc.Load(Application.StartupPath + @"\Settings\DefaultSettings.xml");

				if(this.Version != version)
				{
					// Our Version has changed, write any new settings and their defaults
					this.FillInMissingSettings(version);
					xmlDoc.Save(Application.StartupPath + @"\Settings\DefaultSettings.xml");
				}
			}
			catch
			{
				// Our file doesn't exist, let's create it
				StringBuilder defaultXML = new StringBuilder();
				defaultXML.Append(@"<?xml version='1.0' encoding='utf-8'?>");
				defaultXML.Append(@"<DefaultSettings Version='" + version + "' FirstTime='true'>");
				defaultXML.Append(@"</DefaultSettings>");

				xmlDoc.LoadXml(defaultXML.ToString());
				this.FillInMissingSettings(version);

				xmlDoc.Save(Application.StartupPath + @"\Settings\DefaultSettings.xml");
			}
		}
开发者ID:nguyenhuuhuy,项目名称:mygeneration,代码行数:32,代码来源:DefaultSettings.cs

示例12: btn_thaydoi_Click

 private void btn_thaydoi_Click(object sender, EventArgs e)
 {
     int i = 0;
     XmlNodeList xmlphienam, xmlnghia, xmltienganh;
     XmlDocument xmldoc = new XmlDocument();
     xmldoc.Load("Source.xml");
     xmltienganh = xmldoc.GetElementsByTagName("English");
     xmlphienam = xmldoc.GetElementsByTagName("Phonetic");
     xmlnghia = xmldoc.GetElementsByTagName("Vietnamese");
     if (rd_phienam.Checked == true)
     {
         for (i = 0; i < xmltienganh.Count; i++)
         {
             if (xmltienganh[i].InnerText == txt_timkiem.Text)
             {
                 xmlphienam[i].InnerText = txt_fix.Text;
                 xmldoc.Save("Source.xml");
                 MessageBox.Show("Sửa phiên âm thành công !");
             }
         }
     }
     if (rd_nghia.Checked == true)
     {
         for (i = 0; i < xmltienganh.Count; i++)
         {
             if (xmltienganh[i].InnerText == txt_timkiem.Text)
             {
                 xmlnghia[i].InnerText = txt_nghiaviet.Text;
                 xmldoc.Save("Source.xml");
                 MessageBox.Show("Sửa phiên âm thành công !");
             }
         }
     }
     laydulieu();
 }
开发者ID:mymoon89,项目名称:SPKT_TRANTHITHUY,代码行数:35,代码来源:Form1.cs

示例13: AddFP

		public static void AddFP(long factionID, int addPoints) // Add Faction Points
		{
			CheckFP();
			XmlDocument xmlDoc = new XmlDocument();
			xmlDoc.Load(filename);
			
			XmlNode selectedFaction = xmlDoc.SelectSingleNode("//Faction[@FactionID='" + factionID + "']");
			try
			{
				XmlAttributeCollection factioncheck = selectedFaction.Attributes;
			}
			catch (Exception)
			{
				// Create new faction element.
				XmlNode Faction = xmlDoc.CreateElement("Faction");
				XmlAttribute FactionID = xmlDoc.CreateAttribute("FactionID");
				XmlAttribute CurrentPoints = xmlDoc.CreateAttribute("CurrentPoints");
				XmlNode rootNode = xmlDoc.SelectSingleNode("/FactionPoints");
				FactionID.Value = Convert.ToString(factionID);
				CurrentPoints.Value = Convert.ToString(addPoints); ;
				Faction.Attributes.Append(FactionID);
				Faction.Attributes.Append(CurrentPoints);
				rootNode.AppendChild(Faction);
				xmlDoc.Save(filename);
				return;
			}
			XmlAttributeCollection attributeList = selectedFaction.Attributes;
			XmlNode attributeCurrentPoints = attributeList.Item(1);
			int currentPoints = Convert.ToInt32(attributeCurrentPoints.Value);
			int newPoints = currentPoints + addPoints;
			attributeCurrentPoints.Value = Convert.ToString(newPoints);
			xmlDoc.Save(filename);

		}
开发者ID:rexxar-tc,项目名称:ConquestPlugin,代码行数:34,代码来源:FactionPoints.cs

示例14: Page2

 public Page2()
 {
     InitializeComponent();
     XmlDocument xd = new XmlDocument();
     xd.Load(QQMusic.MainWindow.skins+"\\List\\config.xml");
     xd.Save(QQMusic.MainWindow.skins + "\\List\\config.xml.bak");
     XmlNodeList node = xd.GetElementsByTagName("DlgItem");
     int height=0;
     int temp;
     foreach (XmlNode xn in node)
     {
         XmlElement xe = (XmlElement)xn;
         if (xe.GetAttribute("id").Equals("DlgItem_Advertisement"))
         {
             height = int.Parse(xe.GetAttribute("height"));
             xe.SetAttribute("height","0");
             textBlock1.Inlines.Add("广告高度:" + height+" 像素\n");
         }
     }
     foreach (XmlNode xn in node)
     {
         XmlElement xe = (XmlElement)xn;
         if (xe.GetAttribute("id").IndexOf("List")!=-1)
         {
             temp = height + int.Parse(xe.GetAttribute("height"));
             xe.SetAttribute("height", ""+temp);
             textBlock1.Inlines.Add(xe.GetAttribute("id") + " 高度改变为:" + temp + " 像素\n");
         }
     }
     xd.Save(QQMusic.MainWindow.skins + "\\List\\config.xml");
     textBlock1.Inlines.Add("皮肤配置文件修改完成,已经自动备份。");
 }
开发者ID:chenwp,项目名称:shuax,代码行数:32,代码来源:Page2.xaml.cs

示例15: WriteLog

 public static void WriteLog(string header,List<string> msgs)
 {
     string timeStamp = DateTime.Now.ToString("yyyyMMdd");
     FileInfo activeLogInfo = new FileInfo(Environment.CurrentDirectory + "\\AppLog\\" + "LogFile_" + timeStamp + ".xml");
     XmlDocument logDoc=new XmlDocument();
     if (!activeLogInfo.Exists)
     {
         logDoc.LoadXml("<root></root>");
         logDoc.Save(Environment.CurrentDirectory + "\\AppLog\\" + "LogFile_" + timeStamp + ".xml");
     }
     logDoc.Load(Environment.CurrentDirectory + "\\AppLog\\" + "LogFile_" + timeStamp + ".xml");
     XmlNode newItemNode = XmlHelper.CreateNode(logDoc, "item", "");
     XmlHelper.SetAttribute(newItemNode, "recordedtime", DateTime.Now.ToString());
     XmlHelper.SetAttribute(newItemNode, "header", header);
     foreach(string msg in msgs)
     {
         XmlNode msgNode = XmlHelper.CreateNode(logDoc, "msg", msg);
         newItemNode.AppendChild(msgNode);
     }
     logDoc.SelectSingleNode("/root").AppendChild(newItemNode);
     lock(logDoc)
     {
         logDoc.Save(Environment.CurrentDirectory + "\\AppLog\\" + "LogFile_" + timeStamp + ".xml");
     }
 }
开发者ID:newsike,项目名称:Buffalo-Famework,代码行数:25,代码来源:LogServices.cs


注:本文中的System.Xml.XmlDocument.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。