Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PARSE XML
- public static Dictionary<String,Resource> ParseXML(string filename)
- {
- Dictionary<string, Resource> resources = new Dictionary<string, Resource>();
- try
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(@filename);
- XmlNodeList nodes = doc.DocumentElement.SelectNodes("/GameData/Resources");
- foreach (XmlNode node in nodes)
- {
- Resource r=new Resource();
- r.name = node.SelectSingleNode("Name").InnerText;
- r.amount = Convert.ToDecimal(node.SelectSingleNode("Amount").InnerText);
- r.price = Convert.ToDecimal(node.SelectSingleNode("Price").InnerText);
- resources.Add(r.name,r);
- }
- }
- catch
- {
- MessageBox.Show("Error loading/parsing XML '" + filename + "'");
- }
- return resources;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement