I want to change some values in a bunch of existing XMLs. All of these XMLs are UTF-8 encoded without Byte Order Mark (BOM). My code looks like follow:
private void generateXml(FileInfo newFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(newFile.FullName); string dcSource = this.getDcSource(newFile.Name); string docNumber = this.getDocNumber(newFile.Name); XmlNodeList source = xmlDoc.GetElementsByTagName("dc:source"); source[0].InnerText = dcSource; source = xmlDoc.GetElementsByTagName("docNumber"); source[0].InnerText = docNumber; source = xmlDoc.GetElementsByTagName("referencedFile"); string fileName = newFile.Name.Replace(".xml", ".pdf"); source[0].InnerText = fileName; xmlDoc.Save(newFile.FullName); }I want to keep the existing encoding, but xmlDoc.Save() changes it to utf-8 with BOM. How can I prevent that?