How do I preserve all XML formatting with XDocument?

后端 未结 2 1482
时光取名叫无心
时光取名叫无心 2021-02-14 17:44

I\'m trying to read in an XML configuration file, do a few tweaks (finding and removing or adding an element) and save it again. I want this edit to be as non-intrusive as possi

2条回答
  •  粉色の甜心
    2021-02-14 18:17

    To avoid the declaration in the header of the document you can use the following

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.OmitXmlDeclaration = true;
    
    
            using (XmlWriter xw = XmlWriter.Create(fileName, settings))
            {
                doc.Save(xw);
            }
    

提交回复
热议问题