XDocument doc = XDocument.Load(GetXMLFile()); doc.Root.RemoveAll(); //添加地灾类型 XElement Types = new XElement("Types"); List<DisasterType> types = GetDisasterTypes(); foreach (DisasterType item in types) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Types.AddFirst(Type); } doc.Root.Add(Types); //添加地灾稳定性 XElement Stabilities = new XElement("Stabilities"); List<Stability> stabilities = GetStabilities(); foreach (Stability item in stabilities) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Stabilities.AddFirst(Type); } doc.Root.Add(Stabilities); //添加地灾危害性 XElement Harmfuls = new XElement("Harmfuls"); List<Harmful> harmfuls = GetHarmfuls(); foreach (Harmful item in harmfuls) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Harmfuls.AddFirst(Type); } doc.Root.Add(Harmfuls); //添加潜在风险 XElement Risks = new XElement("Risks"); List<Risk> risks = GetRisks(); foreach (Risk item in risks) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Risks.AddFirst(Type); } doc.Root.Add(Risks); //添加地灾防治方法 XElement Measure_Rs = new XElement("Measure_Rs"); List<Measure_R> measure_Rs = GetMeasure_Rs(); foreach (Measure_R item in measure_Rs) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Measure_Rs.AddFirst(Type); } doc.Root.Add(Measure_Rs); //添加联系人 XElement Contacts = new XElement("Contacts"); List<Contact> contacts = GetContacts(); foreach (Contact item in contacts) { XElement Type = new XElement("Type"); XElement Name = new XElement("Name", item.NAME); Type.SetAttributeValue("CODE", item.CODE); Type.Add(Name); Contacts.AddFirst(Type); } doc.Root.Add(Contacts); doc.Save(GetXMLFile());
时间: 2024-10-13 10:05:38