Working with Google Earth

This is the first in a series looking at how to work with KML files, the file format used by Google Earth. KML is an XML format and, rather than writing lots of XPath queries, it would be nice to generate classes that can be serialised to KML. This way, we get intellisense, and compile-time checking of our code. This part looks at generating classes from the KML schema, to make our lives much easier going forwards.

We will be using the XML Schema Definition Tool (xsd.exe) to generate the .NET classes. We will be outputting in C#, but most languages are supported through the /language option.

Firstly, download the schema itself, and save it to your local disk. I’m saving it to C:\source\kml.xsd.

Then, open up a command prompt and run the following command:

   xsd.exe c:\source\kml.xsd /classes /language:cs /out:c:\source

This will generate a “kml.cs” file containing classes representing the schema, ready to add to the project we will be starting soon.

Advertisements

One thought on “Working with Google Earth

  1. Pingback: Working with Google Earth, Part 3 – Where is the user looking at? « Coding IT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s