public void Save() { var xmlWriter = new CommonXmlWriter(); var root = xmlWriter.CreateRoot("shortcuts"); ShortcutKeies.ForEach((key, value) => root.Append(xmlWriter.CreateElement("shortcut", CreateAttributeInfo(value)))); xmlWriter.Write(xmlPath, root); }
static void Main(string[] args) { var writer = new CommonXmlWriter(); var root = writer.CreateRoot("ServerSettings"); var text = GetInnerXml(File.ReadAllText("serverconfig.xml")); var regex = new Regex("^( |\\t)*<property( |\\t)+name=\"(?<name>.*)\"( |\\t)+value=\"(?<value>.*)\"( |\\t)*\\/>( |\\t)*([\r\n])*( |\t)*<!--(?<description>.*)-->", RegexOptions.Multiline); var match = regex.Match(text); while (match.Success) { var name = match.Groups["name"].ToString(); var value = match.Groups["value"].ToString(); var description = match.Groups["description"].ToString().TrimStart(' ').TrimEnd(' '); string selection = ""; string selectionType = "string"; if (int.TryParse(value, out var iresult)) { selectionType = "integer"; } else if (bool.TryParse(value, out var bresult)) { selectionType = "combo"; selection = "true/false"; } var attributes = new List <AttributeInfo> { new AttributeInfo() { Name = "name", Value = name }, new AttributeInfo() { Name = "value", Value = value }, new AttributeInfo() { Name = "selection", Value = selection }, new AttributeInfo() { Name = "type", Value = selectionType } }; description = AddDescription(attributes, description); var elem = writer.CreateElement("property", attributes.ToArray(), description); root.Append(elem); match = match.NextMatch(); } var memory = new MemoryStream(); writer.Write(memory, root); Console.WriteLine(Encoding.UTF8.GetString(memory.ToArray())); }