c# knowing where/how to put a foreach loop while writing kml files

  • Thread starter Thread starter studysession
  • Start date Start date
S

studysession

Guest
Hi -

I figured out how to write a KML file using static information. I can use variables if I only am writing one location in my KML file.

Not sure how best to describe this:

I need help of taking the following code and knowing where to put a foreach loop to iterate through the information from a file. I keep getting errors because of the placement of ")"'.

Here is my code using static values. I want to pull from a file with a foreach loop. My trouble is the placement of ")" in and outside of the foreach loop.

using System;
using System.IO;
using System.Xml.Linq;

namespace XML_Test_03
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n");

XNamespace n = "http://earth.google.com/kml/2.2";
XElement kmldoc = new XElement(n + "kml", new XElement(n + "Document",
new XElement(n + "name", "HeatMap01"),

new XElement(n + "Placemark", new XAttribute("id", "1"),
new XElement(n + "name", "Baltimore, MD"),
new XElement(n + "description", "Desciption of Baltimore"),
new XElement(n + "Point",
new XElement(n + "coordinates", "-76.61218,39.29038,0"))),

new XElement(n + "Placemark", new XAttribute("id", "2"),
new XElement(n + "name", "Washington DC"),
new XElement(n + "description", "Desciption of Washington DC"),
new XElement(n + "Point",
new XElement(n + "coordinates", "-77.03687,38.90719,0"))),

new XElement(n + "Placemark", new XAttribute("id", "3"),
new XElement(n + "name", "Annapolis, MD"),
new XElement(n + "description", "Desciption of Annapolis, MD"),
new XElement(n + "Point",
new XElement(n + "coordinates", "-76.4921829,38.9784453,0"))),

new XElement(n + "Placemark", new XAttribute("id", "3"),
new XElement(n + "name", "Mt. Airy, MD"),
new XElement(n + "description", "Desciption of Mt. Airy, MD"),
new XElement(n + "Point",
new XElement(n + "coordinates", "-77.154704,39.3762145,0")))));

Console.WriteLine("\n" + kmldoc);

File.WriteAllText(@"c:\tmp\test-kml03.kml", kmldoc.ToString());

}
}
}



Thank you -
Keith

Continue reading...
 
Back
Top