コード例 #1
0
        public void WriteRoute(GpxRoute route)
        {
            Writer_.WriteStartElement("rte");
            WriteTrackOrRoute(route);

            foreach (GpxRoutePoint routePoint in route.RoutePoints)
            {
                WriteRoutePoint("rtept", routePoint);
            }

            Writer_.WriteEndElement();
        }
コード例 #2
0
        private void ReadRouteExtensions(GpxRoute route)
        {
            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 "RouteExtension":
                            ReadGarminTrackOrRouteExtensions(route);
                            break;

                        default:
                            SkipElement();
                            break;
                        }

                        break;
                    }

                    SkipElement();
                    break;

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

            throw new FormatException(elementName);
        }
コード例 #3
0
        private GpxRoute ReadGpxRoute()
        {
            GpxRoute route = new GpxRoute();

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

            string elementName = Reader_.Name;

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

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

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

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

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

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

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

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

                    case "rtept":
                        route.RoutePoints.Add(ReadGpxRoutePoint());
                        break;

                    case "extensions":
                        ReadRouteExtensions(route);
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }