title: Create kml file using xml elements
body: <p>I want to create a kml file in c#. Now I have two problems:</p>
  
  <ol>
  <li><p>What is the synatx to add the kml element in the xml file in order to have the line below in my kml file? </p>
  
  <pre><code>&lt;kml xmlns="http://www.opengis.net/kml/2.2"&gt;
  </code></pre></li>
  <li><p>I have an array of points that i would like to form a linestring. How am I suppose to fill the coordinates element in xml for the kml file?.The following is my code so far.</p></li>
  </ol>
  
  <p><strong>CODE</strong>:</p>
  
  <pre><code>public void MakeKmlFile(string line)
  {
      CoordinateCollection coordinates = new CoordinateCollection();
  
      char[] delimiterLine = { '|' };
      char[] delimiterPoint = { ',' };
      string[] route = line.Split(delimiterLine);
  
      foreach (string point in route)
      {
          string[] route_point = line.Split(delimiterPoint);
          double lat = double.Parse(route_point[1]);
          double lon = double.Parse(route_point[0]);
          coordinates.Add(new Vector(lat, lon));
      }
  
      XmlTextWriter writer = new XmlTextWriter("route.xml", System.Text.Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("Document");
      writer.WriteStartElement("Folder");
      writer.WriteStartElement("name");
      writer.WriteString("route");
      writer.WriteEndElement();
      writer.WriteStartElement("Placemark");
      writer.WriteStartElement("Style");
      writer.WriteStartElement("LineStyle");
      writer.WriteStartElement("color");
      writer.WriteString("ff0000ff");
      writer.WriteEndElement();
      writer.WriteEndElement();
      writer.WriteStartElement("PolyStyle");
      writer.WriteStartElement("fill");
      writer.WriteString("2");
      writer.WriteEndElement();
      writer.WriteEndElement();
      writer.WriteEndElement();
      writer.WriteStartElement("LineString");
      writer.WriteStartElement("coordinates");
  </code></pre>
  
  <p>This is the result i got:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;kml xmlns="http://www.opengis.net/kml/2.2"&gt;
    &lt;Document&gt;
      &lt;Name&gt;Points.kml&lt;/Name&gt;
      &lt;Placemark /&gt;
      &lt;Placemark /&gt;
      &lt;Placemark /&gt;
      &lt;Placemark /&gt;
      &lt;Placemark /&gt;
    &lt;/Document&gt;
  </code></pre>
  
  <p></p>