In my code:
XmlDocument document = new XmlDocument();
XmlElement book = document.CreateElement("book");
document.AppendChild(book);
... // create and add a bunch of nodes
document.Save(filename);
I want to modify my code so that the string <?xml version="1.0"?> is saved at the top of filename. What is the simplest way to do this?
Without manipulating the document, you can provide the
Savemethod with anXmlWriter, which writes the XML declaration by default: