示例#1
0
        public static void ReadGPX(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                using (GpxReader reader = new GpxReader(fs))
                {
                    while (reader.Read())
                    {
                        switch (reader.ObjectType)
                        {
                        case GpxObjectType.Metadata:
                            GpxMetadata metadata = reader.Metadata;
                            Logger.Info("Metadata");
                            break;

                        case GpxObjectType.WayPoint:
                            GpxWayPoint waypoint = reader.WayPoint;
                            Logger.Info("WayPoint");
                            break;

                        case GpxObjectType.Route:
                            GpxRoute route = reader.Route;
                            Logger.Info("Route");
                            break;

                        case GpxObjectType.Track:
                            GpxTrack track = reader.Track;
                            Logger.Info("Track");
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        private GpxWayPoint ReadGpxWayPoint()
        {
            string elementName    = reader.Name;
            bool   isEmptyElement = reader.IsEmptyElement;

            GpxWayPoint wayPoint = new GpxWayPoint();

            GetPointLocation(wayPoint);
            if (isEmptyElement)
            {
                return(wayPoint);
            }

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

                    switch (reader.Name)
                    {
                    case "extensions":
                        ReadWayPointExtensions(wayPoint);
                        break;

                    default:
                        if (!ProcessPointField(wayPoint))
                        {
                            reader.SkipElement();
                        }
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }
示例#3
0
        private void ReadWayPointAliases(GpxWayPoint wayPoint)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "alias":
                        wayPoint.Aliases.Add(reader.ReadElementContentAsString());
                        break;

                    default:
                        reader.SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }
示例#4
0
        private void ReadGarminCategories(GpxWayPoint wayPoint)
        {
            if (Reader_.IsEmptyElement)
            {
                return;
            }

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                case XmlNodeType.Element:
                    switch (Reader_.LocalName)
                    {
                    case "Category":
                        wayPoint.Categories.Add(ReadContentAsString());
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }
示例#5
0
        private void ReadWayPointExtensions(GpxWayPoint wayPoint)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

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

                    if (reader.NamespaceURI == GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE ||
                        reader.NamespaceURI == GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE)
                    {
                        switch (reader.LocalName)
                        {
                        case "WaypointExtension":
                            ReadGarminWayPointExtensions(wayPoint);
                            break;

                        default:
                            reader.SkipElement();
                            break;
                        }

                        break;
                    }

                    if (reader.NamespaceURI == GpxNamespaces.DLG_EXTENSIONS_NAMESPACE)
                    {
                        switch (reader.LocalName)
                        {
                        case "level":
                            wayPoint.Level = reader.ReadElementContentAsInt();
                            break;

                        case "aliases":
                            ReadWayPointAliases(wayPoint);
                            break;

                        default:
                            reader.SkipElement();
                            break;
                        }

                        break;
                    }

                    reader.SkipElement();
                    break;

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

            throw new FormatException(elementName);
        }
示例#6
0
        private void ReadGarminWayPointExtensions(GpxWayPoint wayPoint)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case GpxSymbol.Proximity:
                        wayPoint.Proximity = reader.ReadElementContentAsDouble();
                        break;

                    case "Temperature":
                        wayPoint.Temperature = reader.ReadElementContentAsDouble();
                        break;

                    case "Depth":
                        wayPoint.Depth = reader.ReadElementContentAsDouble();
                        break;

                    case "DisplayMode":
                        wayPoint.DisplayMode = reader.ReadElementContentAsString();
                        break;

                    case "Categories":
                        ReadGarminCategories(wayPoint);
                        break;

                    case "Address":
                        wayPoint.Address = ReadGarminGpxAddress();
                        break;

                    case "PhoneNumber":
                        wayPoint.Phones.Add(ReadGarminGpxPhone());
                        break;

                    case "Samples":
                        wayPoint.Samples = reader.ReadElementContentAsInt();
                        break;

                    case "Expiration":
                        wayPoint.Expiration = reader.ReadElementContentAsDateTime();
                        break;

                    default:
                        reader.SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }
示例#7
0
        private void ReadGarminWayPointExtensions(GpxWayPoint wayPoint)
        {
            if (Reader_.IsEmptyElement) return;

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (Reader_.LocalName)
                        {
                            case "Proximity":
                                wayPoint.Proximity = ReadContentAsDouble();
                                break;
                            case "Temperature":
                                wayPoint.Temperature = ReadContentAsDouble();
                                break;
                            case "Depth":
                                wayPoint.Depth = ReadContentAsDouble();
                                break;
                            case "DisplayMode":
                                wayPoint.DisplayMode = ReadContentAsString();
                                break;
                            case "Categories":
                                ReadGarminCategories(wayPoint);
                                break;
                            case "Address":
                                wayPoint.Address = ReadGarminGpxAddress();
                                break;
                            case "PhoneNumber":
                                wayPoint.Phones.Add(ReadGarminGpxPhone());
                                break;
                            case "Samples":
                                wayPoint.Samples = ReadContentAsInt();
                                break;
                            case "Expiration":
                                wayPoint.Expiration = ReadContentAsDateTime();
                                break;
                            default:
                                SkipElement();
                                break;
                        }

                        break;

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

            throw new FormatException(elementName);
        }
示例#8
0
        public void WriteWayPoint(GpxWayPoint wayPoint)
        {
            Writer_.WriteStartElement("wpt");

            WriteWayOrRoutePoint(wayPoint);

            if (wayPoint.HasWayPointExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement("WaypointExtension", GARMIN_EXTENSIONS_NAMESPACE);

                if (wayPoint.Address != null) WriteAddress("Address", wayPoint.Address);

                if (wayPoint.Categories != null)
                {
                    //<gpxx:Categories><gpxx:Category>Magazine</gpxx:Category></gpxx:Categories>
                    Writer_.WriteStartElement("Categories", GARMIN_EXTENSIONS_NAMESPACE);
                    foreach (string strCategory in wayPoint.Categories)
                    {
                        Writer_.WriteElementString("Category", GARMIN_EXTENSIONS_NAMESPACE, strCategory);
                    }
                    Writer_.WriteEndElement();
                }

                foreach (GpxPhone phone in wayPoint.Phones)
                {
                    WritePhone("PhoneNumber", phone);
                }

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }

            Writer_.WriteEndElement();
        }
示例#9
0
        private void ReadWayPointExtensions(XmlReader reader, GpxWayPoint wayPoint)
        {
            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, wayPoint);
                                    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);
        }
示例#10
0
        private void ReadWayPointAliases(GpxWayPoint wayPoint)
        {
            if (Reader_.IsEmptyElement) return;

            string elementName = Reader_.Name;

            while (Reader_.Read())
            {
                switch (Reader_.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (Reader_.LocalName)
                        {
                            case "alias":
                                wayPoint.Aliases.Add(ReadContentAsString());
                                break;
                            default:
                                SkipElement();
                                break;
                        }

                        break;

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

            throw new FormatException(elementName);
        }
示例#11
0
        public void WriteWayPoint(GpxWayPoint wayPoint)
        {
            Writer_.WriteStartElement("wpt");
            WritePoint(wayPoint);

            if (wayPoint.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");

                if (wayPoint.HasGarminExtensions || wayPoint.HasGarminWaypointExtensions)
                {
                    Writer_.WriteStartElement("WaypointExtension", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE);

                    if (wayPoint.Proximity != null)
                    {
                        Writer_.WriteElementString("Proximity", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Proximity.Value.ToString());
                    }
                    if (wayPoint.Temperature != null)
                    {
                        Writer_.WriteElementString("Temperature", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Temperature.Value.ToString());
                    }
                    if (wayPoint.Depth != null)
                    {
                        Writer_.WriteElementString("Depth", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Depth.Value.ToString());
                    }
                    if (wayPoint.DisplayMode != null)
                    {
                        Writer_.WriteElementString("DisplayMode", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.DisplayMode);
                    }

                    if (wayPoint.Categories.Count != 0)
                    {
                        Writer_.WriteStartElement("Categories", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE);

                        foreach (string category in wayPoint.Categories)
                        {
                            Writer_.WriteElementString("Category", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, category);
                        }

                        Writer_.WriteEndElement();
                    }

                    if (wayPoint.Address != null)
                    {
                        WriteAddress("Address", wayPoint.Address);
                    }

                    foreach (GpxPhone phone in wayPoint.Phones)
                    {
                        WritePhone("PhoneNumber", phone);
                    }

                    if (wayPoint.Samples != null)
                    {
                        Writer_.WriteElementString("Samples", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Samples.Value.ToString());
                    }
                    if (wayPoint.Expiration != null)
                    {
                        Writer_.WriteElementString("Expiration", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, ToGpxDateString(wayPoint.Expiration.Value));
                    }

                    Writer_.WriteEndElement();
                }

                if (wayPoint.Aliases.Count != 0)
                {
                    Writer_.WriteStartElement("aliases", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE);

                    foreach (string alias in wayPoint.Aliases)
                    {
                        Writer_.WriteElementString("alias", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE, alias);
                    }

                    Writer_.WriteEndElement();
                }

                if (wayPoint.Level != null)
                {
                    Writer_.WriteElementString("level", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE, wayPoint.Level.Value.ToString());
                }

                Writer_.WriteEndElement();
            }

            Writer_.WriteEndElement();
        }
示例#12
0
        public void WriteWayPoint(GpxWayPoint wayPoint)
        {
            Writer_.WriteStartElement("wpt");

            WriteWayOrRoutePoint(wayPoint);

            if (wayPoint.HasWayPointExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement("WaypointExtension", GARMIN_EXTENSIONS_NAMESPACE);

                if (wayPoint.Address != null) WriteAddress("Address", wayPoint.Address);

                foreach (GpxPhone phone in wayPoint.Phones)
                {
                    WritePhone("PhoneNumber", phone);
                }

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }

            Writer_.WriteEndElement();
        }
示例#13
0
        private void WriteWayOrRoutePoint(GpxWayPoint wayPoint)
        {
            Writer_.WriteAttributeString("lat", wayPoint.Latitude.ToString(CultureInfo.InvariantCulture));
            Writer_.WriteAttributeString("lon", wayPoint.Longitude.ToString(CultureInfo.InvariantCulture));
            if (wayPoint.Elevation != default(double)) Writer_.WriteElementString("ele", wayPoint.Elevation.ToString(CultureInfo.InvariantCulture));
            if (wayPoint.Time != default(DateTime)) Writer_.WriteElementString("time", ToGpxDateString(wayPoint.Time));
            if (!string.IsNullOrWhiteSpace(wayPoint.Name)) Writer_.WriteElementString("name", wayPoint.Name);
            if (!string.IsNullOrWhiteSpace(wayPoint.Comment)) Writer_.WriteElementString("cmt", wayPoint.Comment);
            if (!string.IsNullOrWhiteSpace(wayPoint.Description)) Writer_.WriteElementString("desc", wayPoint.Description);
            if (!string.IsNullOrWhiteSpace(wayPoint.Source)) Writer_.WriteElementString("src", wayPoint.Source);

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

            if (!string.IsNullOrWhiteSpace(wayPoint.Symbol)) Writer_.WriteElementString("sym", wayPoint.Symbol);
            if (!string.IsNullOrWhiteSpace(wayPoint.Type)) Writer_.WriteElementString("type", wayPoint.Type);
        }
示例#14
0
        public void WriteWayPoint(GpxWayPoint wayPoint)
        {
            Writer_.WriteStartElement("wpt");
            WritePoint(wayPoint);

            if (wayPoint.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");

                if (wayPoint.HasGarminExtensions || wayPoint.HasGarminWaypointExtensions)
                {
                    Writer_.WriteStartElement("WaypointExtension", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE);

                    if (wayPoint.Proximity != null) Writer_.WriteElementString("Proximity", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Proximity.Value.ToString());
                    if (wayPoint.Temperature != null) Writer_.WriteElementString("Temperature", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Temperature.Value.ToString());
                    if (wayPoint.Depth != null) Writer_.WriteElementString("Depth", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Depth.Value.ToString());
                    if (wayPoint.DisplayMode != null) Writer_.WriteElementString("DisplayMode", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.DisplayMode);

                    if (wayPoint.Categories.Count != 0)
                    {
                        Writer_.WriteStartElement("Categories", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE);

                        foreach (string category in wayPoint.Categories)
                        {
                            Writer_.WriteElementString("Category", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, category);
                        }

                        Writer_.WriteEndElement();
                    }

                    if (wayPoint.Address != null) WriteAddress("Address", wayPoint.Address);

                    foreach (GpxPhone phone in wayPoint.Phones)
                    {
                        WritePhone("PhoneNumber", phone);
                    }

                    if (wayPoint.Samples != null) Writer_.WriteElementString("Samples", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, wayPoint.Samples.Value.ToString());
                    if (wayPoint.Expiration != null) Writer_.WriteElementString("Expiration", GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE, ToGpxDateString(wayPoint.Expiration.Value));

                    Writer_.WriteEndElement();
                }

                if (wayPoint.Aliases.Count != 0)
                {
                    Writer_.WriteStartElement("aliases", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE);

                    foreach (string alias in wayPoint.Aliases)
                    {
                        Writer_.WriteElementString("alias", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE, alias);
                    }

                    Writer_.WriteEndElement();
                }

                if (wayPoint.Level != null)
                {
                    Writer_.WriteElementString("level", GpxNamespaces.DLG_EXTENSIONS_NAMESPACE, wayPoint.Level.Value.ToString());
                }

                Writer_.WriteEndElement();
            }

            Writer_.WriteEndElement();
        }
示例#15
0
        private GpxWayPoint ReadGpxWayPoint(XmlReader reader)
        {
            GpxWayPoint wayPoint = new GpxWayPoint();

            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":
                                ReadWayPointExtensions(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);
        }
示例#16
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;
        }
示例#17
0
        private GpxWayPoint ReadGpxWayPoint()
        {
            string elementName = Reader_.Name;
            bool isEmptyElement = Reader_.IsEmptyElement;

            GpxWayPoint wayPoint = new GpxWayPoint();
            GetPointLocation(wayPoint);
            if (isEmptyElement) return wayPoint;

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

                        switch (Reader_.Name)
                        {
                            case "extensions":
                                ReadWayPointExtensions(wayPoint);
                                break;
                            default:
                                if (!ProcessPointField(wayPoint)) SkipElement();
                                break;
                        }

                        break;

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

            throw new FormatException(elementName);
        }
示例#18
0
        private void ReadGarminWayPointExtensions(XmlReader reader, GpxWayPoint wayPoint)
        {
            if (reader.IsEmptyElement) return;

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                            case "Address":
                                wayPoint.Address = ReadGarminGpxAddress(reader);
                                break;
                            case "PhoneNumber":
                                wayPoint.Phones.Add(ReadGarminGpxPhone(reader));
                                break;
                            case "Categories":
                            case "Depth":
                            case "DisplayMode":
                            case "Proximity":
                            case "Temperature":
                            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);
        }
示例#19
0
        private void ReadWayPointExtensions(GpxWayPoint wayPoint)
        {
            if (Reader_.IsEmptyElement) return;

            string elementName = Reader_.Name;

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

                        if (Reader_.NamespaceURI == GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE || Reader_.NamespaceURI == GpxNamespaces.GARMIN_WAYPOINT_EXTENSIONS_NAMESPACE)
                        {
                            switch (Reader_.LocalName)
                            {
                                case "WaypointExtension":
                                    ReadGarminWayPointExtensions(wayPoint);
                                    break;
                                default:
                                    SkipElement();
                                    break;
                            }

                            break;
                        }

                        if (Reader_.NamespaceURI == GpxNamespaces.DLG_EXTENSIONS_NAMESPACE)
                        {
                            switch (Reader_.LocalName)
                            {
                                case "level":
                                    wayPoint.Level = ReadContentAsInt();
                                    break;
                                case "aliases":
                                    ReadWayPointAliases(wayPoint);
                                    break;
                                default:
                                    SkipElement();
                                    break;
                            }

                            break;
                        }

                        SkipElement();
                        break;

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

            throw new FormatException(elementName);
        }