代码:
string path ="C://xxx/file"
XmlDocument xmlDoc = new XmlDocument();
#if NET462
xmlDoc.Load(path);
#else
string content = File.ReadAllText(path);
xmlDoc.LoadXml(content.Trim());
#endif
……
……
#if NET462
xmlDoc.Save(path);
#else
FileStream fs = new FileStream(path, FileMode.Create);
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
XmlWriter writer = XmlWriter.Create(fs, settings);
xmlDoc.Save(writer);
#endif
参考: