Пример #1
0
        private void ReadTrackExtensions(XmlReader reader, GpxTrack track)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.LocalName == "TrackExtension" && reader.NamespaceURI == GARMIN_EXTENSIONS)
                    {
                        ReadGarminTrackOrRouteExtensions(reader, track);
                        break;
                    }

                    SkipElement(reader);
                    break;

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

            throw new FormatException(elementName);
        }
Пример #2
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(Reader_);
                        ObjectType = GpxObjectType.Metadata;
                        return(true);

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

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

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

                    case "extensions":
                        ReadGpxExtensions(Reader_);
                        break;

                    default:
                        throw new FormatException(Reader_.Name);
                    }

                    break;

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

            ObjectType = GpxObjectType.None;
            return(false);
        }
Пример #3
0
        private GpxTrack ReadGpxTrack(XmlReader reader)
        {
            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(reader);
                        break;

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

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

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

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

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

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

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

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

                    default:
                        throw new FormatException(reader.Name);
                    }

                    break;

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

            throw new FormatException(elementName);
        }