Example #1
0
        private void WriteTrackOrRoute(GpxTrackOrRoute trackOrRoute)
        {
            if (trackOrRoute.Name != null)
            {
                Writer_.WriteElementString("name", trackOrRoute.Name);
            }
            if (trackOrRoute.Comment != null)
            {
                Writer_.WriteElementString("cmt", trackOrRoute.Comment);
            }
            if (trackOrRoute.Description != null)
            {
                Writer_.WriteElementString("desc", trackOrRoute.Description);
            }
            if (trackOrRoute.Source != null)
            {
                Writer_.WriteElementString("src", trackOrRoute.Source);
            }

            foreach (GpxLink link in trackOrRoute.Links)
            {
                WriteLink("link", link);
            }

            if (trackOrRoute.Number != null)
            {
                Writer_.WriteElementString("number", trackOrRoute.Number.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (trackOrRoute.Type != null)
            {
                Writer_.WriteElementString("type", trackOrRoute.Type);
            }

            if (trackOrRoute.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement(trackOrRoute is GpxTrack ? "TrackExtension" : "RouteExtension", GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE);

                Writer_.WriteElementString("DisplayColor", GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE, trackOrRoute.DisplayColor.ToString());

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }
        }
Example #2
0
        private void ReadGarminTrackOrRouteExtensions(GpxTrackOrRoute trackOrRoute)
        {
            if (Reader_.IsEmptyElement)
            {
                return;
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:
                    switch (Reader_.LocalName)
                    {
                    case "DisplayColor":
                        trackOrRoute.DisplayColor = (GpxColor)Enum.Parse(typeof(GpxColor), ReadContentAsString(), false);
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != elementName)
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    return;
                }
            }

            throw new FormatException(elementName);
        }