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

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

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


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


        
10条回答
  •  忘掉有多难
    2020-11-29 11:22

    The fastest way would probably be a direct file access.

    using (StreamWriter file = File.AppendText("my.log"))
    {
        file.BaseStream.Seek(-"".Length, SeekOrigin.End);
        file.Write("   New error message.");
    }
    

    But you lose all the nice XML features and may easily corrupt the file.

提交回复
热议问题