public void Save(string xmlPath)
{
var xmlDocument = new XmlDocument();
var xmlDeclaration = xmlDocument.CreateXmlDeclaration(@"1.0", @"utf-8", null);
xmlDocument.InsertBefore(xmlDeclaration, xmlDocument.DocumentElement);
var xmlNode = xmlDocument.AppendChild(xmlDocument.CreateElement(@"localization"));
xmlNode = xmlNode.AppendChild(xmlDocument.CreateElement(@"strings"));
foreach (var entry in _strings.Values)
{
var stringNode = xmlDocument.CreateElement(@"string");
stringNode.SetAttribute(@"key", entry.Key);
if (entry.AliasedKey)
{
stringNode.SetAttribute(@"clone", entry.CloneOf);
}
else if (entry.DeriveFromParent)
{
stringNode.SetAttribute(@"derive", @"true");
}
else if (!string.IsNullOrEmpty(entry.Value))
{
stringNode.SetAttribute(@"value", Utils.NormalizeLineBreaks(entry.Value));
if (entry.BumpVersion)
{
++entry.Version;
}
if (entry.Version != 0)
{
stringNode.SetAttribute(@"version", entry.Version.ToString());
}
}
else
{
continue;
}
xmlNode.AppendChild(stringNode);
}
xmlDocument.Save(xmlPath);
}