Append XML to file without writing it from scratch? [duplicate]
问题 This question already has answers here : Fastest way to add new node to end of an xml? (10 answers) Closed 2 years ago . The standard way to append an XML file in LINQ-to-XML is to read it in, modify the in-memory document, and write the whole file out from scratch. For example: XDocument doc = XDocument.Load("pathToDoc.xml"); doc.Root.Add(new XElement(namespace + "anotherChild", new XAttribute("child-id", childId))); doc.Save("pathToDoc.xml"); Or, with a FileStream : using (FileStream fs =