Пример #1
0
        private void ReadRoutePointExtensions(XmlReader reader, GpxRoutePoint routePoint)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

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

                    if (reader.NamespaceURI == GARMIN_EXTENSIONS)
                    {
                        switch (reader.LocalName)
                        {
                        case "WaypointExtension":
                            ReadGarminWayPointExtensions(reader, routePoint);
                            break;

                        case "RoutePointExtension":
                            ReadGarminRoutePointExtensions(reader, routePoint);
                            break;

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

                        break;
                    }

                    SkipElement(reader);
                    break;

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

            throw new FormatException(elementName);
        }
Пример #2
0
        private void ReadGarminRoutePointExtensions(XmlReader reader, GpxRoutePoint routePoint)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "rpt":
                        routePoint.RoutePoints.Add(ReadGarminAutoRoutePoint(reader));
                        break;

                    case "Subclass":
                    case "Extensions":
                        SkipElement(reader);
                        break;

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

                    break;

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

            throw new FormatException(elementName);
        }
Пример #3
0
        private GpxRoutePoint ReadGpxRoutePoint(XmlReader reader)
        {
            GpxRoutePoint wayPoint = new GpxRoutePoint();

            string elementName    = reader.Name;
            bool   isEmptyElement = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "lat":
                    wayPoint.Latitude = double.Parse(reader.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;

                case "lon":
                    wayPoint.Longitude = double.Parse(reader.Value, CultureInfo.InvariantCulture.NumberFormat);
                    break;
                }
            }

            if (isEmptyElement)
            {
                return(wayPoint);
            }

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

                    switch (reader.Name)
                    {
                    case "ele":
                        wayPoint.Elevation = ReadContentAsDouble(reader);
                        break;

                    case "time":
                        wayPoint.Time = ReadContentAsDateTime(reader);
                        break;

                    case "name":
                        wayPoint.Name = ReadContentAsString(reader);
                        break;

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

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

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

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

                    case "sym":
                        wayPoint.Symbol = ReadContentAsString(reader);
                        break;

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

                    case "extensions":
                        ReadRoutePointExtensions(reader, wayPoint);
                        break;

                    case "magvar":
                    case "geoidheight":
                    case "fix":
                    case "sat":
                    case "hdop":
                    case "vdop":
                    case "pdop":
                    case "ageofdgpsdata":
                    case "dgpsid":
                        SkipElement(reader);
                        break;

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

                    break;

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

            throw new FormatException(elementName);
        }