Ejemplo n.º 1
0
        public bool Read()
        {
            if (ObjectType == GpxObjectType.None)
            {
                return(false);
            }

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:

                    switch (Reader_.Name)
                    {
                    case "metadata":
                        Metadata   = ReadGpxMetadata();
                        ObjectType = GpxObjectType.Metadata;
                        return(true);

                    case "wpt":
                        WayPoint   = ReadGpxWayPoint();
                        ObjectType = GpxObjectType.WayPoint;
                        return(true);

                    case "rte":
                        Route      = ReadGpxRoute();
                        ObjectType = GpxObjectType.Route;
                        return(true);

                    case "trk":
                        Track      = ReadGpxTrack();
                        ObjectType = GpxObjectType.Track;
                        return(true);

                    default:
                        SkipElement();
                        break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (Reader_.Name != "gpx")
                    {
                        throw new FormatException(Reader_.Name);
                    }
                    ObjectType = GpxObjectType.None;
                    return(false);
                }
            }

            ObjectType = GpxObjectType.None;
            return(false);
        }
Ejemplo n.º 2
0
        public void WriteTrack(GpxTrack track)
        {
            Writer_.WriteStartElement("trk");
            WriteTrackOrRoute(track);

            foreach (GpxTrackSegment segment in track.Segments)
            {
                WriteTrackSegment("trkseg", segment);
            }

            Writer_.WriteEndElement();
        }
Ejemplo n.º 3
0
        private void ReadTrackExtensions(GpxTrack track)
        {
            if (Reader_.IsEmptyElement)
            {
                return;
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:

                    if (Reader_.NamespaceURI == GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE)
                    {
                        switch (Reader_.LocalName)
                        {
                        case "TrackExtension":
                            ReadGarminTrackOrRouteExtensions(track);
                            break;

                        default:
                            SkipElement();
                            break;
                        }

                        break;
                    }

                    SkipElement();
                    break;

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

            throw new FormatException(elementName);
        }
Ejemplo n.º 4
0
        private GpxTrack ReadGpxTrack()
        {
            GpxTrack track = new GpxTrack();

            if (Reader_.IsEmptyElement)
            {
                return(track);
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:

                    switch (Reader_.Name)
                    {
                    case "name":
                        track.Name = ReadContentAsString();
                        break;

                    case "cmt":
                        track.Comment = ReadContentAsString();
                        break;

                    case "desc":
                        track.Description = ReadContentAsString();
                        break;

                    case "src":
                        track.Source = ReadContentAsString();
                        break;

                    case "link":
                        track.Links.Add(ReadGpxLink());
                        break;

                    case "number":
                        track.Number = int.Parse(ReadContentAsString());
                        break;

                    case "type":
                        track.Type = ReadContentAsString();
                        break;

                    case "trkseg":
                        track.Segments.Add(ReadGpxTrackSegment());
                        break;

                    case "extensions":
                        ReadTrackExtensions(track);
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }