private void WriteAddress(string elementName, GpxAddress address) { Writer_.WriteStartElement(elementName, GARMIN_EXTENSIONS_NAMESPACE); if (!string.IsNullOrEmpty(address.StreetAddress)) { Writer_.WriteElementString("StreetAddress", GARMIN_EXTENSIONS_NAMESPACE, address.StreetAddress); } if (!string.IsNullOrEmpty(address.City)) { Writer_.WriteElementString("City", GARMIN_EXTENSIONS_NAMESPACE, address.City); } if (!string.IsNullOrEmpty(address.State)) { Writer_.WriteElementString("State", GARMIN_EXTENSIONS_NAMESPACE, address.State); } if (!string.IsNullOrEmpty(address.Country)) { Writer_.WriteElementString("Country", GARMIN_EXTENSIONS_NAMESPACE, address.Country); } if (!string.IsNullOrEmpty(address.PostalCode)) { Writer_.WriteElementString("PostalCode", GARMIN_EXTENSIONS_NAMESPACE, address.PostalCode); } Writer_.WriteEndElement(); }
private GpxAddress ReadGarminGpxAddress(XmlReader reader) { GpxAddress address = new GpxAddress(); if (reader.IsEmptyElement) { return(address); } string elementName = reader.Name; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "StreetAddress": if (string.IsNullOrEmpty(address.StreetAddress)) { address.StreetAddress = ReadContentAsString(reader); break; } address.StreetAddress += " " + ReadContentAsString(reader); break; case "City": address.City = ReadContentAsString(reader); break; case "State": address.State = ReadContentAsString(reader); break; case "Country": address.Country = ReadContentAsString(reader); break; case "PostalCode": address.PostalCode = ReadContentAsString(reader); break; 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(address); } } throw new FormatException(elementName); }