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


C# XmlDocument.Save方法代码示例

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


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

示例1: SaveStatistik

    public void SaveStatistik(string statText, string name)
    {
        CheckFile ();
        // Создаем корневой элемент
        XmlDocument xmlDoc = new XmlDocument ();
        if(File.Exists(filePatch))
            xmlDoc.Load (filePatch);

        XmlNode xRoot;
        XmlNode findNode = xmlDoc.SelectSingleNode ("Stats"); // найти корневой элемент
        if ( findNode == null)
            xRoot = xmlDoc.CreateElement ("Stats"); 	// Создать корневой элемент
        else
            xRoot = findNode;

        xmlDoc.AppendChild (xRoot);

        //Временные преременные для дочерних элементов и атрибутов
        XmlElement taskElement1; //Элемент 1-го уровня

        findNode = xmlDoc.SelectSingleNode ("Stats/" + name);
        if ( findNode == null) {
            taskElement1 = xmlDoc.CreateElement (name);
            taskElement1.InnerText = statText;
            xRoot.AppendChild (taskElement1);
        } else {
            findNode.InnerText = statText;
        }

        /////////////////////////////////////////////////////////////
        xmlDoc.Save ("Data/Save/Stats.xml");
    }
开发者ID:Antis28,项目名称:JuperFly,代码行数:32,代码来源:SaveStats.cs

示例2: Button1_ServerClick

 protected void Button1_ServerClick(object sender, EventArgs e)
 {
     try
     {
         string currency = idChoice.Value;
         XmlDocument doc = new XmlDocument();
         string url = Server.MapPath("../data/xml/configproduct.xml");
         XmlTextReader reader = new XmlTextReader(url);
         doc.Load(reader);
         reader.Close();
         if (doc.IsReadOnly)
         {
             diverr.Visible = true;
             diverr.InnerHtml = "File XML đã bị khóa. Không thể thay đổi";
             return;
         }
         XmlNode nodeEdit = doc.SelectSingleNode("root/product[nameappunit='currency']/unit");
         string value = nodeEdit.InnerText;
         if (!value.Equals(currency))
         {
             nodeEdit.InnerText = currency;
             doc.Save(url);
             Application["currency"] = currency;
             diverr.Visible = true;
             diverr.InnerHtml = "Đã thay đổi cách hiển thị tiền tệ";
         }
         else
         {
             diverr.Visible = true;
             diverr.InnerHtml = "Hệ thống đang hiển thị kiểu tiền này.";
         }
     }catch
     {}
 }
开发者ID:BGCX261,项目名称:zlap-svn-to-git,代码行数:34,代码来源:ChangeCurrency.ascx.cs

示例3: Main

    //Using the DOM parser write a program to delete from catalog.xml
    //all albums having price > 20.
    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        string fileLocation = @"..\..\catalogue.xml";
        doc.Load(fileLocation);
        Console.WriteLine("Document Loaded");

        XmlNode rootNode = doc.DocumentElement;
        var count = rootNode.ChildNodes.Count;

        for (int i = 0; i < count; i++)
        {
            XmlNode album = rootNode.ChildNodes[i];
            XmlNode albumNode = album.FirstChild;

            while (albumNode != null)
            {
                XmlNode nextSibling = albumNode.NextSibling;
                double price = double.Parse(albumNode["Price"].InnerText);

                if (price > 20)
                {
                    album.RemoveChild(albumNode);
                }

                albumNode = nextSibling;
            }
        }

        doc.Save(fileLocation);
    }
开发者ID:razsilev,项目名称:TelerikAcademy_Homework,代码行数:33,代码来源:Program.cs

示例4: RunFileAction

	private static bool RunFileAction (XmlNode fileElement)
	{
		string path = GetAttribute (fileElement, "Path");
		XmlDocument doc = new XmlDocument ();
		try {
			doc.Load (path);
		} catch {
			Console.WriteLine ("ERROR: Could not open {0}.", path);
			return false;
		}
		
		Console.WriteLine ("Processing {0}...", path);
		
		foreach (XmlNode element in fileElement.SelectNodes ("Replace"))
			if (!ReplaceNode (fileElement.OwnerDocument, doc, element))
				return false;
		
		foreach (XmlNode element in fileElement.SelectNodes ("Insert"))
			if (!InsertNode (fileElement.OwnerDocument, doc, element))
				return false;
		
		foreach (XmlNode element in fileElement.SelectNodes ("Remove"))
			if (!RemoveNodes (doc, element))
				return false;
		
		doc.Save (path);
		Console.WriteLine ("{0} saved.", path);
		return true;
	}
开发者ID:JohnThomson,项目名称:taglib-sharp,代码行数:29,代码来源:XmlInjector.cs

示例5: btnSave_Click

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (tbxStart.Text == "" || tbxEnd.Text == "" || DateTime.Parse(tbxStart.Text) > DateTime.Parse(tbxEnd.Text))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "alert('时间选择不正确')", true);
            return;
        }
        //保存活动有限期限到配置文件
        string config = Server.MapPath("/config/app.config");
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(config);

        XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
        foreach (XmlElement element in topM)
        {
            if (element.Attributes["key"].Value == "quzhouDate")
            {
                element.Attributes["value"].Value = tbxStart.Text.Trim()+","+tbxEnd.Text.Trim();
            }
        }
        xmldoc.Save(config);

        string[] ticketId = ConfigurationManager.AppSettings["ticketId"].Split(',');
        List<Ticket> listTicket = new List<Ticket>();
        for (int i = 0; i < ticketId.Length; i++)
        {
            listTicket.Add(bllTicket.GetTicket(int.Parse(ticketId[i])));
        }
        bllta.SaveDate(DateTime.Parse(tbxStart.Text), DateTime.Parse(tbxEnd.Text), listTicket);
        BindData();
        ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "alert('保存成功')", true);
    }
开发者ID:phiree,项目名称:testttt,代码行数:32,代码来源:DateSettings.aspx.cs

示例6: EncryptFile

    public static void EncryptFile(string path)
    {
        if (!File.Exists(path))
        {
            Debug.Log("File Not Found At: " + path);
            return;
        }

        XmlDocument xmlFile = new XmlDocument();
        xmlFile.Load(path);
        XmlElement xmlRoot = xmlFile.DocumentElement;

        if (xmlRoot.ChildNodes.Count > 1)
        {
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("86759426197648123460789546213421");
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (xmlRoot.InnerXml);
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;
            ICryptoTransform cTransform = rDel.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
            xmlRoot.InnerXml = Convert.ToBase64String (resultArray, 0, resultArray.Length);
        }

        xmlFile.Save(path);
    }
开发者ID:jcabe4,项目名称:Reignite,代码行数:27,代码来源:XMLFileManager.cs

示例7: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("../../../catalog.xml");
        XmlNode rootNode = doc.DocumentElement;
        List<XmlNode> albumsForDeleting = new List<XmlNode>();
        foreach (XmlNode node in rootNode.ChildNodes)
        {
            int price = int.Parse(node["price"].InnerText);
            if (price > 20)
            {
                albumsForDeleting.Add(node);

            }
        }

        foreach (var album in albumsForDeleting)
        {
            doc.DocumentElement.RemoveChild(album);
        }

        doc.Save("../../newCatalog.xml");

        //For save the changes to the same file
        //doc.Save("../../catalog.xml");
    }
开发者ID:nim-ohtar,项目名称:TelerikAcademy-2,代码行数:26,代码来源:Program.cs

示例8: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(@"..\..\..\catalogue.xml");
        XmlNode rootNode = doc.DocumentElement;

        for (int i = 0; i < rootNode.ChildNodes.Count; i++)
        {
            XmlNode node = rootNode.ChildNodes[i];

            foreach (XmlNode albumPrice in node.ChildNodes)
            {
                // if the node is the price node
                if (albumPrice.Name == "price")
                {
                    // take the price
                    double price = double.Parse(albumPrice.InnerText);
                    if (price > 20.00)
                    {
                        rootNode.RemoveChild(node); // remove the node
                        i--; // decrementing i so that we won't miss a node
                    }
                }
            }
        }

        doc.Save(@"..\..\..\catalogueUnderTwentyPrice.xml");
    }
开发者ID:YavorIT,项目名称:DatabaseOnlineCourseTelerikHW,代码行数:28,代码来源:DOMDelete.cs

示例9: Main

    static void Main()
    {
        XmlDocument document = new XmlDocument();
        document.Load(filePath);

        XmlNode rootNode = document.DocumentElement;

        var nodesToRemove = new List<XmlNode>();

        foreach (XmlNode node in rootNode.ChildNodes)
        {
            decimal price = decimal.Parse(node["price"].InnerText, System.Globalization.NumberStyles.Currency, culture);
            if (price > 20)
            {
                nodesToRemove.Add(node);
            }
        }

        foreach (var node in nodesToRemove)
        {
            rootNode.RemoveChild(node);
        }

        document.Save(filePath);
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:25,代码来源:RemoveWithDOMParser.cs

示例10: Module_Action_Delete

 private string Module_Action_Delete()
 {
     string tmpstr = "";
     string trootstr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("root")));
     string tvaluestr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("value")));
     if (com.fileExists(Server.MapPath(trootstr)))
     {
       try
       {
     string tnode, tfield, tbase;
     XmlDocument tXMLDom = new XmlDocument();
     tXMLDom.Load(Server.MapPath(trootstr));
     XmlNode tXmlNode = tXMLDom.SelectSingleNode("/xml/configure");
     tnode = tXmlNode.ChildNodes.Item(0).InnerText;
     tfield = tXmlNode.ChildNodes.Item(1).InnerText;
     tbase = tXmlNode.ChildNodes.Item(2).InnerText;
     XmlNode tXmlNodeDel = tXMLDom.SelectSingleNode("/xml/" + tbase + "/" + tnode + "[" + cls.getLRStr(tfield, ",", "left") + "='" + tvaluestr + "']");
     if (tXmlNodeDel != null)
     {
       tXmlNodeDel.ParentNode.RemoveChild(tXmlNodeDel);
       tXMLDom.Save(Server.MapPath(trootstr));
     }
     tmpstr = jt.itake("global.lng_common.delete-succeed", "lng");
       }
       catch
       {
     tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
       }
     }
     else tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
     tmpstr = config.ajaxPreContent + tmpstr;
     return tmpstr;
 }
开发者ID:dengfan,项目名称:jtbc-plus,代码行数:33,代码来源:manage-interface.cs

示例11: SaveDataForCurrentUser

    public static void SaveDataForCurrentUser()
    {
        try
        {
            string currentUser = TransitionData.GetUsername();

            _document = new XmlDocument();

            XmlElement completedLevels = _document.CreateElement(COMPLETED_LEVELS_NODE_NAME);

            foreach (string answer in _completedLevels)
            {
                XmlElement completedLevelNode = _document.CreateElement(answer);

                completedLevels.AppendChild(completedLevelNode);
            }

            _document.AppendChild(completedLevels);

            _document.Save(GetSaveDataPathForUser(currentUser));
        }
        catch(Exception e)
        {
            Debug.LogError(e);
        }
    }
开发者ID:ednedfed,项目名称:WordGuess,代码行数:26,代码来源:SaveData.cs

示例12: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("../../items.xml");

        string culture = doc.DocumentElement.Attributes["culture"].Value;
        CultureInfo numberFormat = new CultureInfo(culture);

        // Promotion: decrease twice the price of all beers
        foreach (XmlNode node in doc.DocumentElement)
        {
            if (node.Attributes["type"].Value == "beer")
            {
                string currentPriceStr = node["price"].InnerText;
                decimal currentPrice = Decimal.Parse(currentPriceStr, numberFormat);
                decimal newPrice = currentPrice / 2;
                node["price"].InnerText = newPrice.ToString(numberFormat);
            }
        }

        Console.WriteLine("Modified XML document:");
        Console.WriteLine(doc.OuterXml);

        doc.Save("../../itemsNew.xml");
    }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:25,代码来源:ModifyXMLwithDOM.cs

示例13: OpenAppXMLFile

    public XmlDocument OpenAppXMLFile()
    {
        string App_Path = @ConfigurationManager.AppSettings["Data_Path"].ToString();
        App_Path = App_Path + "Items.xml";

        if (File.Exists(@App_Path))
        {
            try
            {
                xmldoc = new XmlDocument();
                xmldoc.Load(@App_Path);
            }
            catch (Exception ex)
            {
                ///  Do not currently understand how to terminate the ThreadStart in the event of a failure
                GlobalClass.ErrorMessage = "Error in AppThreads(OpenAppFile): " + ex.Message;

            }

        }
        else
        {
            xmldoc = new XmlDocument();
            XmlNode iheader = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xmldoc.AppendChild(iheader);
            XmlElement root = xmldoc.CreateElement("dataroot");
            xmldoc.InsertAfter(root, iheader);
            xmldoc.Save(@App_Path);

        }

         return  xmldoc;
    }
开发者ID:emcgurty,项目名称:ASP_NET_with_XML_List,代码行数:33,代码来源:GetXMLdoc.cs

示例14: Main

    static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("../../catalogue.xml");

        XmlNode rootNode = doc.DocumentElement;

        HashSet<string> artistsSet = new HashSet<string>();
        List<XmlNode> albumsToDelete = new List<XmlNode>();

        decimal searchedPrice = 15;
        foreach (XmlNode node in rootNode.ChildNodes)
        {
            decimal parsedPrice = decimal.Parse(node["price"].InnerText);

            if (parsedPrice > searchedPrice)
            {
                albumsToDelete.Add(node);
            }
        }

        foreach (var album in albumsToDelete)
        {
            rootNode.RemoveChild(album);
        }

        // see the created catalogue_new.xml file to see that files are deleted
        doc.Save("../../catalogue_new.xml");
    }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:29,代码来源:DeleteFromXMLUsingDOMParser.cs

示例15: DeleteAttribute

    /// <summary>
    /// 删除XmlNode属性
    /// 使用示列:
    /// XmlHelper.DeleteAttribute(path, nodeName, "");
    /// XmlHelper.DeleteAttribute(path, nodeName, attributeName,attributeValue);
    /// </summary>
    /// <param name="path">文件路径</param>
    /// <param name="nodeName">节点名称</param>
    /// <param name="attributeName">属性名称</param>
    /// <returns>void</returns>
    public static void DeleteAttribute(string path, string nodeName, string attributeName)
    {
        if (attributeName.Equals(""))
        {
            return;
        }

        try
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlElement element = doc.SelectSingleNode(nodeName) as XmlElement;
            if (element == null)
            {
                throw new Exception("节点元素不存在!");
            }
            else
            {
                element.RemoveAttribute(attributeName);
                doc.Save(path);
            }
        }
        catch
        { }
    }
开发者ID:hj-nicholas,项目名称:BaseFrame,代码行数:36,代码来源:XmlHelper.cs


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