Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.04 KB | None | 0 0
  1.         //PARSE XML
  2.         public static Dictionary<String,Resource> ParseXML(string filename)
  3.         {
  4.             Dictionary<string, Resource> resources = new Dictionary<string, Resource>();
  5.  
  6.             try
  7.             {
  8.                 XmlDocument doc = new XmlDocument();
  9.                 doc.Load(@filename);
  10.            
  11.                 XmlNodeList nodes = doc.DocumentElement.SelectNodes("/GameData/Resources");
  12.            
  13.                 foreach (XmlNode node in nodes)
  14.                 {
  15.                     Resource r=new Resource();
  16.      
  17.                     r.name = node.SelectSingleNode("Name").InnerText;
  18.                     r.amount = Convert.ToDecimal(node.SelectSingleNode("Amount").InnerText);
  19.                     r.price = Convert.ToDecimal(node.SelectSingleNode("Price").InnerText);
  20.      
  21.                     resources.Add(r.name,r);
  22.                 }
  23.  
  24.             }
  25.             catch
  26.             {
  27.                 MessageBox.Show("Error loading/parsing XML '" + filename + "'");
  28.             }
  29.        
  30.             return resources;
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement