Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. public bool SaveXML(string filename)
  2.         {
  3.             XmlDocument document = new XmlDocument();
  4.             XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", null, null);
  5.             declaration.Encoding = "utf-8";
  6.  
  7.             document.AppendChild(declaration);
  8.             XmlElement root = document.CreateElement("", "Bank", "");
  9.             root.SetAttribute("version", "1");
  10.             document.AppendChild(root);
  11.  
  12.             // Add different race sections
  13.             XmlElement protoss = document.CreateElement("", "Section", "");
  14.             protoss.SetAttribute("name", "ProtossBuildOrders");
  15.             XmlElement zerg = document.CreateElement("", "Section", "");
  16.             zerg.SetAttribute("name", "ZergBuildOrders");
  17.             XmlElement terran = document.CreateElement("", "Section", "");
  18.             terran.SetAttribute("name", "TerranBuildOrders");
  19.  
  20.             root.AppendChild(protoss);
  21.             root.AppendChild(zerg);
  22.             root.AppendChild(terran);
  23.  
  24.             foreach (BuildOrder build in buildOrders)
  25.             {
  26.                 XmlElement key = document.CreateElement("Key");
  27.                 key.SetAttribute("name", build.Key);
  28.  
  29.                 XmlElement value = document.CreateElement("Value");
  30.                 value.SetAttribute("string", build.Value);
  31.  
  32.                 key.AppendChild(value);
  33.  
  34.                 switch (build.Race)
  35.                 {
  36.                     case (BuildRace.Protoss):
  37.                         protoss.AppendChild(key);
  38.                         break;
  39.                     case (BuildRace.Zerg):
  40.                         zerg.AppendChild(key);
  41.                         break;
  42.                     case (BuildRace.Terran):
  43.                         terran.AppendChild(key);
  44.                         break;
  45.                 }
  46.             }
  47.  
  48.             document.Save(filename);
  49.  
  50.             return true;
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement