Fastest way to add new node to end of an xml?

前端 未结 10 669
深忆病人
深忆病人 2020-11-29 10:21

I have a large xml file (approx. 10 MB) in following simple structure:


   .......
   .......         


        
10条回答
  •  自闭症患者
    2020-11-29 11:12

    Try this out:

            var doc = new XmlDocument();
            doc.LoadXml("This is my first error");
    
            XmlNode root = doc.DocumentElement;
    
            //Create a new node.
            XmlElement elem = doc.CreateElement("error");
            elem.InnerText = "This is my error";
    
            //Add the node to the document.
            if (root != null) root.AppendChild(elem);
    
            doc.Save(Console.Out);
            Console.ReadLine();
    

提交回复
热议问题