public static ObjectDb FromXml(string xml) { ObjectDb res = new ObjectDb(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNode n = doc.SelectSingleNode("/database"); res.timestamp = int.Parse(n.Attributes["timestamp"].InnerText); foreach (XmlNode node in n.ChildNodes) { if (node.Name == "categories") { foreach (XmlNode subn in node.ChildNodes) { res.Categories.Add(int.Parse(subn.Attributes["id"].InnerText), subn.InnerText); } } else if (node.Name == "object") { ObjectDbEntry tmp = ObjectDbEntry.FromXml(node.ChildNodes); res.Entries.Add(node.Attributes["id"].InnerText, tmp); if (tmp.model.Trim() != "") { res.IdToModel.Add(node.Attributes["id"].InnerText, tmp.model); } } } return(res); }
public static ObjectDbEntry FromXml(XmlNodeList nodes) { ObjectDbEntry res = new ObjectDbEntry(); foreach (XmlNode n in nodes) { switch (n.Name) { case "name": res.name = n.InnerText; break; case "type": res.type = n.InnerText; break; case "model": res.model = n.InnerText; break; case "flags": res.Known = int.Parse(n.Attributes["known"].InnerText); res.Complete = int.Parse(n.Attributes["complete"].InnerText); break; case "category": res.Category = int.Parse(n.Attributes["id"].InnerText); break; case "notes": res.notes = n.InnerText; break; case "files": res.files = n.InnerText; break; case "field": res.Fields.Add(ObjectDbField.FromXml(n)); break; } } return(res); }