示例#1
0
        private void WritePerson(string elementName, GpxPerson person)
        {
            Writer_.WriteStartElement(elementName);

            if (!IsNullOrWhiteSpace(person.Name))
            {
                Writer_.WriteElementString("name", person.Name);                                   //IsNullOrWhiteSpace
            }
            if (person.Email != null)
            {
                WriteEmail("email", person.Email);
            }

            Writer_.WriteEndElement();
        }
示例#2
0
        private GpxPerson ReadGpxPerson(XmlReader reader)
        {
            GpxPerson person = new GpxPerson();

            if (reader.IsEmptyElement)
            {
                return(person);
            }

            string elementName = reader.Name;

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

                    switch (reader.Name)
                    {
                    case "name":
                        person.Name = ReadContentAsString(reader);
                        break;

                    case "email":
                        person.Email = ReadGpxEmail(reader);
                        break;

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

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

                    break;

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

            throw new FormatException(elementName);
        }