public void AddOrUpdateTech(Technology newTech) { techs[newTech.Name] = newTech; }
private void loadXMLButton_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(xmlSrcFilenameTextBox.Text); } catch (FileNotFoundException fne) { string message = "could not find XML file \'" + fne.FileName + "\'"; string caption = "File Not Found"; statusMessage.Text = message; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } ClearRooms(); // TODO: code to load rooms, items, techs XmlNodeList xmlRoomList = xmlDoc.GetElementsByTagName("room"); foreach (XmlNode xmlRoom in xmlRoomList) { Room room = new Room(); room.Name = xmlRoom.Attributes.GetNamedItem("name").Value; XmlNodeList xmlItemList = xmlRoom.ChildNodes; foreach (XmlNode xmlItem in xmlItemList) { Item item = new Item(); item.Name = xmlItem.Attributes.GetNamedItem("name").Value; XmlNodeList xmlTechList = xmlItem.ChildNodes; foreach (XmlNode xmlTech in xmlTechList) { Technology tech = new Technology(); if (!xmlTech.HasChildNodes) { continue; } for (int i = 0; i < xmlTech.ChildNodes.Count; ++i) { switch (xmlTech.ChildNodes[i].Name) { case "name": if (xmlTech.ChildNodes[i].FirstChild != null) { tech.Name = xmlTech.ChildNodes[i].FirstChild.Value; } break; case "image_name": if (xmlTech.ChildNodes[i].FirstChild != null) { tech.ImageName = xmlTech.ChildNodes[i].FirstChild.Value; } break; case "summary": if (xmlTech.ChildNodes[i].FirstChild != null) { tech.Summary = xmlTech.ChildNodes[i].FirstChild.Value; } break; case "description": if (xmlTech.ChildNodes[i].FirstChild != null) { tech.Description = xmlTech.ChildNodes[i].FirstChild.Value; } break; case "more_info_url": if (xmlTech.ChildNodes[i].FirstChild != null) { tech.MoreInfoURL = xmlTech.ChildNodes[i].FirstChild.Value; } break; default: break; } } item.AddOrUpdateTech(tech); } room.AddOrUpdateItem(item); } AddRoom(room); } }