private Bank CreateBank(XDocument xmlDocument) { Bank bank = new Bank(); //Check for bank-tag var bankNode = xmlDocument.Descendants("Bank").FirstOrDefault(); if (bankNode == null) { return(null); } //Check for version var versionAttribute = bankNode.Attribute("version"); if (versionAttribute != null) { bank.Version = versionAttribute.Value; } //Add sections XAttribute nameAttribute; foreach (var sectionNode in bankNode.Descendants("Section")) { Bank.Section section = new Bank.Section(); bank.Sections.Add(section); nameAttribute = sectionNode.Attribute("name"); if (nameAttribute != null) { section.Name = nameAttribute.Value; } //Add keys foreach (var keyNode in sectionNode.Descendants("Key")) { Bank.Key key = new Bank.Key(); key.Section = section; section.Keys.Add(key); nameAttribute = keyNode.Attribute("name"); if (nameAttribute != null) { key.Name = nameAttribute.Value; } //Key type/value are stored in the attributes of a single child "Value" node foreach (var item in keyNode.Descendants()) { var valueAttribute = item.Attributes().FirstOrDefault(); var tag = item.Name.ToString(); var type = valueAttribute.Name.ToString(); var value = valueAttribute.Value; key.Items.Add(new Bank.Item { Name = tag, Type = type, Value = value }); } } } return(bank); }
private XElement CreateSection(Bank.Section section) { return(new XElement("Section", new XAttribute("name", section.Name), CreateKeys(section.Keys))); }