public void OnClickSave() { XElement tmproot = new XElement("root"); //add current edit root m_TreeParser.GenXML(tmproot, m_Root); //check other content and check id Check(tmproot, m_Root.ID); //ready to save using (FileStream fs = new FileStream(m_strDataPath, FileMode.Create)) { XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.IndentChars = "\t"; setting.NewLineChars = "\n"; setting.Encoding = Encoding.UTF8; using (XmlWriter xw = XmlWriter.Create(fs, setting)) { tmproot.WriteTo(xw); } } }