Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool SaveXML(string filename)
- {
- try
- {
- XmlDocument document = new XmlDocument();
- XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", null, null);
- declaration.Encoding = "utf-8";
- document.AppendChild(declaration);
- XmlElement root = document.CreateElement("", "Bank", "");
- root.SetAttribute("version", "1"); // Don't know what this is for
- document.AppendChild(root);
- // Add different race sections
- XmlElement protossElement = document.CreateElement("", "Section", "");
- protossElement.SetAttribute("name", "ProtossBuildOrders");
- XmlElement zergElement = document.CreateElement("", "Section", "");
- zergElement.SetAttribute("name", "ZergBuildOrders");
- XmlElement terranElement = document.CreateElement("", "Section", "");
- terranElement.SetAttribute("name", "TerranBuildOrders");
- root.AppendChild(protossElement);
- root.AppendChild(zergElement);
- root.AppendChild(terranElement);
- // Add the builds to the XML file
- foreach (BuildOrder build in buildOrders)
- {
- XmlElement key = document.CreateElement("Key");
- key.SetAttribute("name", build.Key);
- XmlElement value = document.CreateElement("Value");
- value.SetAttribute("string", build.Value);
- key.AppendChild(value);
- switch (build.Race)
- {
- case (BuildRace.Protoss):
- protossElement.AppendChild(key);
- break;
- case (BuildRace.Zerg):
- zergElement.AppendChild(key);
- break;
- case (BuildRace.Terran):
- terranElement.AppendChild(key);
- break;
- }
- }
- document.Save(filename);
- return true;
- }
- catch
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement