Monday, July 07, 2008

Auto-Generate KML C# Classes

Using the xsd.exe tool (in a default installation, you can find it here: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin), you can auto-generate KML C# classes. Make sure you have ogckm122.xsd (here), atom-author-link.xsd (here), and xAL.xsd (here) in the directory where you are executing the xsd command.

>xsd /c ogckml22.xsd atom -author-link.xsd xAL.xsd

This will generate a C# file called ogckml22_atom-author-link_xAL.cs.

Thanks to these two blog posts for the help: xsd command and multiple xsd files and Error generating classes for schema 'MySchema.xsd'.


Anonymous said...

It worked! Thank you very much.

Anonymous said...

Do you have any examples of the XMLSerialization? I'm having some trouble getting the base serializer to recognize the classes generated from the 2.2 schema.

Lach said...

While you show how to generate the class file, if you ever try to deserialize something into these classes it fails with an error along the lines of "Member DocumentType.Items of type[] hides base class member AbstractFeatureType.Items of type[]. Use XmlElementAttribute or XmlAttributeAttribute to specify a new name."

Unfortunatly I don't know how to fix it, i'm trying to search ATM.