Esempio n. 1
0
        public static void Write(KMLData data, string fileName)
        {
            using (XmlWriter writer = XmlWriter.Create(fileName, new XmlWriterSettings {
                CloseOutput = true, Indent = true
            }))
            {
                writer.WriteStartDocument(false);
                writer.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
                writer.WriteStartElement("Document");

                if (!string.IsNullOrEmpty(data.Name))
                {
                    writer.WriteElementString("name", data.Name);
                }
                if (!string.IsNullOrEmpty(data.Description))
                {
                    writer.WriteElementString("description", data.Description);
                }

                foreach (var item in data)
                {
                    Write("Placemark", item, writer);
                }

                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
Esempio n. 2
0
        public static KMLData Read(string fileName)
        {
            KMLData result = new KMLData();

            using (XmlReader reader = XmlReader.Create(fileName))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name.ToUpper())
                        {
                        case "NAME":
                        {
                            result.Name = TinyKML.ReadString(reader);
                            break;
                        }

                        case "DESCRIPTION":
                        {
                            result.Name = TinyKML.ReadString(reader);
                            break;
                        }

                        case "PLACEMARK":
                        {
                            result.Add(TinyKML.ReadPlacemark(reader));
                            break;
                        }
                        }
                    }
                }
            }

            return(result);
        }