public void SaveToXml(string file) { XmlDocument doc = new XmlDocument(); // 加入声明 XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.AppendChild(dec); // 加入根元素,即Table XmlElement root = doc.CreateElement("DrawDocument"); doc.AppendChild(root); XmlElement itemdoc = doc.CreateElement("PageObject"); root.AppendChild(itemdoc); DocToXml(doc, itemdoc); int n = ObjList.Count(); for (int i = 0; i < n; i++) { XmlElement item = doc.CreateElement("DrawObject"); root.AppendChild(item); ObjList[i].WriteToXml(doc, item); } // 保存文件 XmlTextWriter tr = new XmlTextWriter(file, null); tr.Formatting = Formatting.Indented; doc.WriteContentTo(tr); tr.Close(); }
public String CreateObjName() { int No = 1; for (int n = 0; n <= ObjList.Count() - 1; n++) { if (ObjList[n].ObjName == (ActivedObjType.ToString() + No.ToString())) { No = No + 1; } } return(ActivedObjType.ToString() + No.ToString()); }