Example #1
0
        private GpxCopyright ReadGpxCopyright(XmlReader reader)
        {
            GpxCopyright copyright = new GpxCopyright();

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

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "author":
                    copyright.Author = reader.Value;
                    break;
                }
            }

            if (isEmptyElement)
            {
                return(copyright);
            }

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

                    switch (reader.Name)
                    {
                    case "year":
                        copyright.Year = int.Parse(ReadContentAsString(reader));
                        break;

                    case "license":
                        copyright.Licence = new Uri(ReadContentAsString(reader));
                        break;

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

                    break;

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

            throw new FormatException(elementName);
        }
Example #2
0
 private void WriteCopyright(string elementName, GpxCopyright copyright)
 {
     Writer_.WriteStartElement(elementName);
     Writer_.WriteAttributeString("author", copyright.Author);
     if (copyright.Year != default(int))
     {
         Writer_.WriteElementString("year", copyright.Year.ToString());
     }
     if (copyright.Licence != null)
     {
         Writer_.WriteElementString("licence", copyright.Licence.ToString());
     }
     Writer_.WriteEndElement();
 }