/// <summary> /// Writes the MilitaryGroup to a file in xml format. /// </summary> public void WriteToFile(string path, MilitaryGroup military) { if (m_hook != null) { m_hook(military); } // Ensure that all units have IDs set. foreach (var unit in military.Organizations.SelectMany(o => o.AllUnits)) { if (unit.Data.Id == 0) { throw new Exception("Unit has no ID: " + unit.Data.Name); } } foreach (var cdr in military.Organizations.SelectMany(o => o.AllCommanders)) { if (cdr.Data.Id == 0) { throw new Exception("Commander has no ID: " + cdr.Data.LastName); } } using (MilitaryXmlWriter writer = new MilitaryXmlWriter(path, m_headers, m_mode)) { writer.Formatting = Formatting.Indented; writer.Indentation = 0; writer.IndentChar = ' '; writer.WriteStartElement("xml"); writer.WriteStartElement("mil"); foreach (var organization in military.Organizations) { organization.XmlWrite(writer); } writer.WriteEndElement(); writer.WriteUsedHeaders(); writer.WriteEndElement(); writer.Close(); } }
/// <summary> /// Writes this object to Xml, using the XmlElementName attribute of the class /// as the outer tag. /// </summary> public static void XmlWrite <T>(this T me, MilitaryXmlWriter writer) where T : IXmlWriteable { writer.WriteStartElement(me.TagName); me.XmlWriteThis(writer); writer.WriteEndElement(); }