public string Load(string path = "..\\..\\Sample.gpx")
        {
            string result = null;

            try
            {
                var xdocument = XDocument.Load(path);
                var defaultNS = xdocument.Root.GetDefaultNamespace();
                if (string.IsNullOrEmpty(defaultNS.NamespaceName))
                {
                    var xml         = xdocument.ToString();
                    var indexOfGpx  = xml.IndexOf("<gpx ");
                    var insertIndex = indexOfGpx + 5;
                    xml = xml.Insert(5, "xmlns = \"http://www.topografix.com/GPX/1/1\" ");
                    SetGpxWithMemoryStream(xml);
                }
                else
                {
                    SetGpxWithNormalFileStream(path);
                }
                result = "";
            }
            catch (Exception e)
            {
                result = e.Message;
                gpx    = new gpxType();
            }
            return(result);
        }
        private void SetGpxWithNormalFileStream(string path)
        {
            XmlSerializer ser = new XmlSerializer(typeof(gpxType));

            using (FileStream str = new FileStream(path, FileMode.Open))
            {
                gpx = (gpxType)ser.Deserialize(str);
            }
        }
        private void SetGpxWithMemoryStream(string xml)
        {
            XmlSerializer ser = new XmlSerializer(typeof(gpxType));

            using (var stream = xml.ToStream())
            {
                gpx = (gpxType)ser.Deserialize(stream);
            }
        }
 public void Save(string fileName, gpxType gpxData)
 {
     try
     {
         using (StreamWriter stream = new StreamWriter(fileName))
         {
             XmlSerializer ser = new XmlSerializer(typeof(gpxType));
             ser.Serialize(stream, gpxData);
         }
     }
     catch (Exception e)
     {
     }
 }