Пример #1
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            this.Version   = reader.GetAttributeDouble("version");
            this.Generator = reader.GetAttribute("generator");

            List <Node>      nodes      = null;
            List <Way>       ways       = null;
            List <Relation>  relations  = null;
            List <Changeset> changesets = null;
            List <GpxFile>   gpxFiles   = null;

            reader.GetElements(
                new Tuple <string, Action>(
                    "api", () =>
            {
                this.Api = new Capabilities();
                (this.Api as IXmlSerializable).ReadXml(reader);
                reader.Read();
            }),
                new Tuple <string, Action>(
                    "bounds", () =>
            {
                this.Bounds = new Bounds();
                (this.Bounds as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "node", () =>
            {
                var node = new Node();
                (node as IXmlSerializable).ReadXml(reader);
                if (nodes == null)
                {
                    nodes = new List <Node>();
                }
                nodes.Add(node);
            }),
                new Tuple <string, Action>(
                    "way", () =>
            {
                var way = new Way();
                (way as IXmlSerializable).ReadXml(reader);
                if (ways == null)
                {
                    ways = new List <Way>();
                }
                ways.Add(way);
            }),
                new Tuple <string, Action>(
                    "relation", () =>
            {
                var relation = new Relation();
                (relation as IXmlSerializable).ReadXml(reader);
                if (relations == null)
                {
                    relations = new List <Relation>();
                }
                relations.Add(relation);
            }),
                new Tuple <string, Action>(
                    "changeset", () =>
            {
                var changeset = new Changeset();
                (changeset as IXmlSerializable).ReadXml(reader);
                if (changesets == null)
                {
                    changesets = new List <Changeset>();
                }
                changesets.Add(changeset);
            }),
                new Tuple <string, Action>(
                    "user", () =>
            {
                this.User = new User();
                (this.User as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "gpx_file", () =>
            {
                var gpxFile = new GpxFile();
                (gpxFile as IXmlSerializable).ReadXml(reader);
                if (gpxFiles == null)
                {
                    gpxFiles = new List <GpxFile>();
                }
                gpxFiles.Add(gpxFile);
            }));

            if (nodes != null)
            {
                this.Nodes = nodes.ToArray();
            }
            if (ways != null)
            {
                this.Ways = ways.ToArray();
            }
            if (relations != null)
            {
                this.Relations = relations.ToArray();
            }
            if (changesets != null)
            {
                this.Changesets = changesets.ToArray();
            }
            if (gpxFiles != null)
            {
                this.GpxFiles = gpxFiles.ToArray();
            }
        }
Пример #2
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            this.Version   = reader.GetAttributeDouble("version");
            this.Generator = reader.GetAttribute("generator");

            List <Node>      nodes      = null;
            List <Way>       ways       = null;
            List <Relation>  relations  = null;
            List <Changeset> changesets = null;
            List <GpxFile>   gpxFiles   = null;
            List <User>      users      = null;
            List <Note>      notes      = null;

            reader.GetElements(
                new Tuple <string, Action>(
                    "api", () =>
            {
                this.Api = new Capabilities();
                (this.Api as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "bounds", () =>
            {
                this.Bounds = new Bounds();
                (this.Bounds as IXmlSerializable).ReadXml(reader);
                reader.Read();
            }),
                new Tuple <string, Action>(
                    "node", () =>
            {
                var node = new Node();
                (node as IXmlSerializable).ReadXml(reader);
                if (nodes == null)
                {
                    nodes = new List <Node>();
                }
                nodes.Add(node);
            }),
                new Tuple <string, Action>(
                    "way", () =>
            {
                var way = new Way();
                (way as IXmlSerializable).ReadXml(reader);
                if (ways == null)
                {
                    ways = new List <Way>();
                }
                ways.Add(way);
            }),
                new Tuple <string, Action>(
                    "relation", () =>
            {
                var relation = new Relation();
                (relation as IXmlSerializable).ReadXml(reader);
                if (relations == null)
                {
                    relations = new List <Relation>();
                }
                relations.Add(relation);
            }),
                new Tuple <string, Action>(
                    "changeset", () =>
            {
                var changeset = new Changeset();
                (changeset as IXmlSerializable).ReadXml(reader);
                if (changesets == null)
                {
                    changesets = new List <Changeset>();
                }
                changesets.Add(changeset);
            }),
                new Tuple <string, Action>(
                    "user", () =>
            {
                var user = new User();
                (user as IXmlSerializable).ReadXml(reader);
                if (users == null)
                {
                    users = new List <User>();
                }
                users.Add(user);
            }),
                new Tuple <string, Action>(
                    "note", () =>
            {
                var note = new Note();
                (note as IXmlSerializable).ReadXml(reader);
                if (note.Id.HasValue)         // Ignore Notes missing content.
                {
                    if (notes == null)
                    {
                        notes = new List <Note>();
                    }
                    notes.Add(note);
                }
            }),
                new Tuple <string, Action>(
                    "policy", () =>
            {
                this.Policy = new Policy();
                (this.Policy as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "permissions", () =>
            {
                this.Permissions = new Permissions();
                (this.Permissions as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "preferences", () =>
            {
                this.Preferences = new Preferences();
                (this.Preferences as IXmlSerializable).ReadXml(reader);
            }),
                new Tuple <string, Action>(
                    "gpx_file", () =>
            {
                var gpxFile = new GpxFile();
                (gpxFile as IXmlSerializable).ReadXml(reader);
                if (gpxFiles == null)
                {
                    gpxFiles = new List <GpxFile>();
                }
                gpxFiles.Add(gpxFile);
            }));

            if (nodes != null)
            {
                this.Nodes = nodes.ToArray();
            }
            if (ways != null)
            {
                this.Ways = ways.ToArray();
            }
            if (relations != null)
            {
                this.Relations = relations.ToArray();
            }
            if (changesets != null)
            {
                this.Changesets = changesets.ToArray();
            }
            if (gpxFiles != null)
            {
                this.GpxFiles = gpxFiles.ToArray();
            }
            if (users != null)
            {
                if (users.Count == 1)
                {
                    this.User = users[0];
                }
                else
                {
                    this.Users = users.ToArray();
                }
            }
            if (notes != null)
            {
                this.Notes = notes.ToArray();
            }
        }