Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML-Encoding without BOM

$
0
0

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?


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>