private ExportGPXSettings GetSettingsFromValue(string v) { var result = new ExportGPXSettings(); if (!string.IsNullOrEmpty(v)) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(v); XmlNodeList nl = doc.SelectNodes("/settings/setting"); foreach (XmlNode n in nl) { switch (n.Attributes["name"].Value) { case "FileName": result.FileName = n.Attributes["value"].Value; break; case "Version": result.Version = Version.Parse(n.Attributes["value"].Value); break; } } } catch { result = null; } } return(result); }
private string GetSettingsFromValue(ExportGPXSettings s) { var result = ""; if (s != null) { var doc = new XmlDocument(); var root = doc.CreateElement("settings"); doc.AppendChild(root); var q = doc.CreateElement("setting"); var attr = doc.CreateAttribute("name"); var txt = doc.CreateTextNode("FileName"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.FileName ?? ""); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); q = doc.CreateElement("setting"); attr = doc.CreateAttribute("name"); txt = doc.CreateTextNode("Version"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.Version.ToString()); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); q = doc.CreateElement("setting"); attr = doc.CreateAttribute("name"); txt = doc.CreateTextNode("AddChildWaypoints"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.AddChildWaypoints.ToString()); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); var sb = new StringBuilder(); var tr = new System.IO.StringWriter(sb); var wr = new XmlTextWriter(tr); wr.Formatting = Formatting.None; doc.Save(wr); wr.Close(); result = sb.ToString(); } return(result); }
private string GetSettingsFromValue(ExportGPXSettings s) { var result = ""; if (s != null) { var doc = new XmlDocument(); var root = doc.CreateElement("settings"); doc.AppendChild(root); var q = doc.CreateElement("setting"); var attr = doc.CreateAttribute("name"); var txt = doc.CreateTextNode("FileName"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.FileName ?? ""); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); q = doc.CreateElement("setting"); attr = doc.CreateAttribute("name"); txt = doc.CreateTextNode("Version"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.Version.ToString()); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); q = doc.CreateElement("setting"); attr = doc.CreateAttribute("name"); txt = doc.CreateTextNode("AddChildWaypoints"); attr.AppendChild(txt); q.Attributes.Append(attr); attr = doc.CreateAttribute("value"); txt = doc.CreateTextNode(s.AddChildWaypoints.ToString()); attr.AppendChild(txt); q.Attributes.Append(attr); root.AppendChild(q); var sb = new StringBuilder(); var tr = new System.IO.StringWriter(sb); var wr = new XmlTextWriter(tr); wr.Formatting = Formatting.None; doc.Save(wr); wr.Close(); result = sb.ToString(); } return result; }
private ExportGPXSettings GetSettingsFromValue(string v) { var result = new ExportGPXSettings(); if (!string.IsNullOrEmpty(v)) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(v); XmlNodeList nl = doc.SelectNodes("/settings/setting"); foreach (XmlNode n in nl) { switch (n.Attributes["name"].Value) { case "FileName": result.FileName = n.Attributes["value"].Value; break; case "Version": result.Version = Version.Parse(n.Attributes["value"].Value); break; case "AddChildWaypoints": result.AddChildWaypoints = bool.Parse(n.Attributes["value"].Value); break; } } } catch { result = null; } } return result; }