Esempio n. 1
0
        public void WriteMetadata(GpxMetadata metadata)
        {
            Writer_.WriteStartElement("metadata");

            if (metadata.Name != null)
            {
                Writer_.WriteElementString("name", metadata.Name);
            }
            if (metadata.Description != null)
            {
                Writer_.WriteElementString("desc", metadata.Description);
            }
            if (metadata.Author != null)
            {
                WritePerson("author", metadata.Author);
            }
            if (metadata.Copyright != null)
            {
                WriteCopyright("copyright", metadata.Copyright);
            }
            if (metadata.Link != null)
            {
                WriteLink("link", metadata.Link);
            }
            if (metadata.Time != null)
            {
                Writer_.WriteElementString("time", ToGpxDateString(metadata.Time.Value));
            }
            if (metadata.Keywords != null)
            {
                Writer_.WriteElementString("keywords", metadata.Keywords);
            }
            if (metadata.Bounds != null)
            {
                WriteBounds("bounds", metadata.Bounds);
            }

            Writer_.WriteEndElement();
        }
Esempio n. 2
0
        private GpxMetadata ReadGpxMetadata()
        {
            GpxMetadata metadata = new GpxMetadata();

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

            string elementName = Reader_.Name;

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

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

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

                    case "author":
                        metadata.Author = ReadGpxPerson();
                        break;

                    case "copyright":
                        metadata.Copyright = ReadGpxCopyright();
                        break;

                    case "link":
                        metadata.Link = ReadGpxLink();
                        break;

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

                    case "keywords":
                        metadata.Keywords = ReadContentAsString();
                        break;

                    case "bounds":
                        ReadGpxBounds();
                        break;

                    default:
                        SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }